seal
Defines if instances of the map should be sealed in development.
Boolean
If true
, in development, instances of this object will be sealed. In strict mode errors will be thrown when undefined properties are set. This is the default
behavior of extended DefineMaps:
"use strict";
var Person = DefineMap.extend({});
var me = new Person();
me.age = 33 //-> throws "TypeError: Can't add property age, object is not extensible"
If false
, the object will not be sealed. This is the default behavior of
unextended DefineMaps. Use get and set to get and set values:
var person = new DefineMap();
person.set("first","Justin");
person.set("last","Meyer");
person.get("first") //-> "Justin"
person.get("last") //-> "Meyer"
It is also possible to extend a sealed object and unseal it:
"use strict";
var Person = DefineMap.extend({});
var Programmer = Person.extend({seal: false}, {})
var me = new Programmer();
me.age = 33; // no error thrown
Set seal
to false
on objects that have an indeterminate number of properties:
var Style = DefineMap.extend({
seal: false
},{
cssText: {
get: function(){
return _.map(this.get(), function(val, prop){
return prop+": "+val;
}).join(";")
}
}
});
var style = new Style();
style.set("color","green");
style.set("font","awesome");
style.cssText //-> "color:green; font: awesome;"