Skip to content

Instantly share code, notes, and snippets.

@spearwolf
Last active August 29, 2015 14:21
Show Gist options
  • Save spearwolf/0b213a2ae8bf04e324c0 to your computer and use it in GitHub Desktop.
Save spearwolf/0b213a2ae8bf04e324c0 to your computer and use it in GitHub Desktop.
javascript patterns
// 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