Skip to content

Instantly share code, notes, and snippets.

@TJkrusinski
Last active August 29, 2015 14:00
Show Gist options
  • Save TJkrusinski/11327962 to your computer and use it in GitHub Desktop.
Save TJkrusinski/11327962 to your computer and use it in GitHub Desktop.
'use strict';
/**
* Typical constructor
*/
function Human (props) {
this.props = props || {};
};
Human.prototype.speak = function () {
console.log.apply(console, arguments);
};
var tj = new Human({name: 'tj'});
tj.speak('This is a basic JS constructor');
/**
* Self constructing constructor?
*/
function Dog (props) {
if (!(this instanceof Dog)) return new Dog(props);
this.props = props || {};
};
Dog.prototype.bark = function () {
console.log.apply(console, arguments);
};
var fido = Dog({name: 'fido'});
fido.bark('I am an annoying dog');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment