Skip to content

Instantly share code, notes, and snippets.

@talentless
Created April 10, 2012 18:33
Show Gist options
  • Save talentless/2353541 to your computer and use it in GitHub Desktop.
Save talentless/2353541 to your computer and use it in GitHub Desktop.
Crafty.c("Tag", {init: function() { this.requires("2D"); this._defineGetterSetter_setter(); this._defineGetterSetter_defineProperty(); this._tag = 0; },
_tag: 0,
_defineGetterSetter_setter: function() {
this.__defineSetter__('tag', function (v) { this._attr('_tag', v); });
this.__defineGetter__('tag', function () { return this._tag; });
},
_defineGetterSetter_defineProperty: function() {
Object.defineProperty(this, 'tag', {
set: function (v) { this._attr('_tag', v); }
, get: function () { return this._tag; }
, configurable: true
});
},
getChildByTag: function(tag) {
for (var i = 0; i < this._children.length; i++) {
if (this._children[i].tag == tag) { return this._children[i]; }
}
},
removeChildByTag: function(tag) {
for (var i = 0; i < this._children.length; i++) {
if (this._children[i].tag == tag) { this.detach(this._children[i]); }
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment