Last active
January 2, 2016 17:49
-
-
Save emartinez-usgs/8339637 to your computer and use it in GitHub Desktop.
Functions and Constructors
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
var MyClass = function () { | |
console.log(this); | |
}; | |
new MyClass(); // Constructor | |
MyClass(); // Function |
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
var MyClass = function () { | |
}; | |
var myOne = new MyClass(), | |
myTwo = MyClass(); | |
console.log(myOne); | |
console.log(myTwo); |
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
var MyClass = function () { | |
return this; | |
}; | |
var myOne = new MyClass(), | |
myTwo = MyClass(); | |
console.log(myOne); | |
console.log(myTwo); |
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
var MyClass = function (value) { | |
this.myValue = value; | |
}; | |
MyClass.prototype.getValue = function () { | |
return this.myValue; | |
}; | |
var myOne = new MyClass('text for one'), | |
myTwo = MyClass('text for two'); | |
console.log(myOne.getValue()); | |
console.log(myTwo.getValue()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment