Last active
August 29, 2015 14:00
-
-
Save TJkrusinski/11327962 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
'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