Last active
August 29, 2015 14:21
-
-
Save spearwolf/0b213a2ae8bf04e324c0 to your computer and use it in GitHub Desktop.
javascript patterns
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
// javascript inheritance example | |
// ECMAScript 5.1 (ECMA-262) / Javascript 1.8.5 | |
function Foo ( name ) { | |
this.name = name; | |
} | |
function Bar () { | |
Foo.call( this, 'Bar' ); | |
} | |
Bar.prototype = Object.create( Foo.prototype ); | |
Bar.prototype.constructor = Bar; | |
Bar.prototype.whoami = function () { | |
console.log( this.name ); | |
} | |
// Usage example .. | |
bar = new Bar(); | |
bar.whoami(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment