Skip to content

Instantly share code, notes, and snippets.

@sdesai
Created June 28, 2013 18:54
Show Gist options
  • Save sdesai/5887102 to your computer and use it in GitHub Desktop.
Save sdesai/5887102 to your computer and use it in GitHub Desktop.
"test subclass can get() superclass attributes" : function() {
function MyBase() {
MyBase.superclass.constructor.apply(this, arguments);
}
Y.extend(MyBase, Y.Base, null, {
ATTRS : {
foo : {
value: 10
},
bar : {
valueFn: function() {
return 20;
}
},
baz : {
value: 30
}
},
NAME: 'myBase'
});
function MyExtendedBase() {
MyExtendedBase.superclass.constructor.apply(this, arguments);
}
Y.extend(MyExtendedBase, MyBase, null, {
ATTRS : {
testsetter : {
value: 1000,
setter: function(val) {
return this.get("foo") + this.get("bar") + this.get("baz");
}
},
testvaluefn : {
valueFn: function() {
return (this.get("foo") + this.get("bar") + this.get("baz")) * 2;
}
},
testgetter : {
getter : function() {
return (this.get("foo") + this.get("bar") + this.get("baz")) * 3;
}
}
},
NAME: 'myExtendedBase'
});
var o = new MyExtendedBase();
Y.Assert.areEqual(60, o.get("testsetter"), "setter not able to see superclass attrs");
Y.Assert.areEqual(120, o.get("testvaluefn"), "valueFn not able to see superclass attrs");
Y.Assert.areEqual(180, o.get("testgetter"), "getter not able to see superclass attrs");
var o = new MyExtendedBase({
foo: 20,
bar: 40,
baz: 60
});
Y.Assert.areEqual(120, o.get("testsetter"), "setter not able to see superclass attrs");
Y.Assert.areEqual(240, o.get("testvaluefn"), "valueFn not able to see superclass attrs");
Y.Assert.areEqual(360, o.get("testgetter"), "getter not able to see superclass attrs");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment