Skip to content

Instantly share code, notes, and snippets.

@emartinez-usgs
Last active January 2, 2016 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emartinez-usgs/8339637 to your computer and use it in GitHub Desktop.
Save emartinez-usgs/8339637 to your computer and use it in GitHub Desktop.
Functions and Constructors
var MyClass = function () {
console.log(this);
};
new MyClass(); // Constructor
MyClass(); // Function
var MyClass = function () {
};
var myOne = new MyClass(),
myTwo = MyClass();
console.log(myOne);
console.log(myTwo);
var MyClass = function () {
return this;
};
var myOne = new MyClass(),
myTwo = MyClass();
console.log(myOne);
console.log(myTwo);
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