-
Notifications
You must be signed in to change notification settings - Fork 0
Object.parse
James Westgate edited this page Jan 18, 2014
·
4 revisions
Creates and/or updates an object hierarchy. If one or more parts of the namespace exist, then they are used instead. Any new namespace objects are added to any existing namespaces.
Example 1
object.Parse('acme.sales');
acme.sales.target = 500;
alert('Target: ' + acme.sales.target);Example 2
Namespaces can be created, then extended using the Object.extend method.
Object.parse('acme.marketing').extend(function() {
this.getBudget = function() {
return 600;
};
});
alert('Budget: ' + acme.marketing.getBudget());This namespace is extended with a function that is called with the context (this) set to the namespace object returned from Object.parse
Example 3
References to namespaces are returned from the namespace function.
var ns = Object.parse('acme.sales.forecasting').extend(function() {
this.notify = function(msg) {
alert(msg);
}
});
ns.notify('Sales are up!'); //alerts 'Sales are up'