Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Class.extend takes a function that returns the options object
- // it is passed the accessor function generated in the Pvt.js example above
- var Person = Class.extend(function(pvt) {
- // private static member
- var species = "Homo sapien";
- return {
- init: function(isDancing) {
- // pvt(this).invisible === undefined
- // pvt(this).hasSword === undefined
- pvt(this).dancing = isDancing;
- // pvt(this).dancing === isDancing
- },
- dance: function() {
- return pvt(this).dancing;
- },
- getSpecies: function() {
- return species ;
- }
- };
- });
- var Ninja = Person.extend(function(pvt) {
- return {
- init: function(hasSword){
- pvt(this).invisible = true;
- this._super( false );
- pvt(this).hasSword = hasSword || true;
- // pvt(this).dancing === false
- },
- dance: function(){
- // Call the inherited version of dance()
- return this._super();
- },
- swingSword: function(){
- return pvt(this).hasSword;
- }
- };
- });
- var p = new Person(true);
- p.dance(); // => true
- var n = new Ninja();
- n.dance(); // => false
- n.swingSword(); // => true
- // Should all be true
- p instanceof Person && p instanceof Class &&
- n instanceof Ninja && n instanceof Person && n instanceof Class;
Add Comment
Please, Sign In to add comment