Skip to content

Instantly share code, notes, and snippets.

@v3rt1go
Created October 11, 2015 10:16
Show Gist options
  • Save v3rt1go/90446f9113281d996f7c to your computer and use it in GitHub Desktop.
Save v3rt1go/90446f9113281d996f7c to your computer and use it in GitHub Desktop.
// function form
function fnForm() {
console.log('function form: ', this);
}
fnForm(); // function form - this is the global object - (window)
// method form
var parent = function parent() {
var p = {};
p.methodForm = function methodForm() {
console.log('method form: ', this);
};
this.applyForm = function applyForm() {
console.log('apply form: ', this);
}
return p;
}
var f = parent();
f.methodForm();
// constructor form
var fn = new fnForm();
// apply/call form
fnForm.call(parent, 1, 2);
fnForm.apply(parent, [1, 2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment