No need for an injection scope as we can also just use Base.each() in combination with a side-car.

This commit is contained in:
Jürg Lehni 2011-11-24 14:54:04 +01:00
parent b96cd4e1c8
commit d9777111dc

View file

@ -293,26 +293,24 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
statics: { statics: {
_id: 0 _id: 0
} }
}, new function() { // Injection scope to produce getter setters for properties }, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'],
// We need setters because we want to call _changed() if a property was // Produce getter/setters for properties. We need setters because we want to
// modified. // call _changed() if a property was modified.
return Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'], function(name) {
function(name) { var part = Base.capitalize(name),
var part = Base.capitalize(name), name = '_' + name;
name = '_' + name; this['get' + part] = function() {
this['get' + part] = function() { return this[name];
return this[name]; };
}; this['set' + part] = function(value) {
this['set' + part] = function(value) { if (value != this[name]) {
if (value != this[name]) { this[name] = value;
this[name] = value; // #locked does not change appearance, all others do:
// #locked does not change appearance, all others do: this._changed(name === '_locked'
this._changed(name === '_locked' ? ChangeFlag.ATTRIBUTE : Change.ATTRIBUTE);
? ChangeFlag.ATTRIBUTE : Change.ATTRIBUTE); }
} };
}; }, {}), /** @lends Item# */{
}, {});
}, /** @lends Item# */{
// Note: These properties have their getter / setters produced in the // Note: These properties have their getter / setters produced in the
// injection scope above. // injection scope above.