Created
March 28, 2012 17:46
-
-
Save cayasso/2228653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// con solo prototype extend | |
var Persona = Class.extend('Persona', { | |
saludar: function () { | |
return 'my method'; | |
} | |
}) | |
var adulto = Persona(); | |
console.log(adulto.saludar()); // my method | |
// con solo class method extend | |
var Persona = Class.extend('Persona', { | |
saludar: function () { | |
return 'my method'; | |
} | |
}, true) | |
var adulto = Persona(); | |
console.log(Persona.saludar()); // my method | |
console.log(adulto.saludar()); // Error | |
// con class y prototype methods extend | |
var Persona = Class.extend('Persona', { | |
saludar: function () { | |
return 'my method'; | |
} | |
}, { | |
hi: function () { | |
return 'my hi'; | |
} | |
}) | |
var adulto = Persona(); | |
console.log(Persona.saludar()); // my method | |
console.log(adulto.hi()); // my hi | |
// con class y prototype e init extend | |
var Persona = Class.extend('Persona', { | |
saludar: function () { | |
return 'my method'; | |
} | |
}, { | |
init: function (name) { | |
this.name = name; | |
}, | |
hi: function () { | |
return 'hi ' + this.name; | |
} | |
}) | |
var adulto = Persona('Walter'); | |
console.log(Persona.saludar()); // my method | |
console.log(adulto.hi()); // hi Walter | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment