Last active
August 29, 2015 14:00
-
-
Save nealfennimore/11186094 to your computer and use it in GitHub Desktop.
Console Log and Object Calls
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 config = { | |
openOnLoad: false, | |
defaultName: "Jane", | |
options: ["Red", "Green", "Blue"], | |
print: function() { | |
console.log("Here in config"); | |
} | |
}; | |
console.log(config.print()); // => "Here in config" | |
config.print; // => [Function] | |
// ----------------------------- | |
var config = { | |
openOnLoad: false, | |
defaultName: "Jane", | |
options: ["Red", "Green", "Blue"], | |
print: function() { | |
console.log("Open on load: " + this.openOnLoad); | |
console.log("Default name: " + this.defaultName); | |
console.log("Options: " + this.options); | |
} | |
}; | |
config.print(); | |
// ------------------------------ | |
function print() { | |
console.log(this); | |
console.log("Open on load: " + this.openOnLoad); | |
console.log("Default name: " + this.defaultName); | |
console.log("Options: " + this.options); | |
} | |
print() // Nada. | |
//------------------------------ | |
function print(config) { | |
console.log(config); | |
console.log("Open on load: " + config.openOnLoad); | |
console.log("Default name: " + config.defaultName); | |
console.log("Options: " + config.options); | |
} | |
print(config) // Works. | |
//------------------------------ | |
function print() { | |
console.log(this); | |
console.log("Open on load: " + this.openOnLoad); | |
console.log("Default name: " + this.defaultName); | |
console.log("Options: " + this.options); | |
} | |
// Puts config variable into function | |
print.apply(config); | |
// bind | |
var boundPrint = print.bind(config); | |
console.log(print); // => [Function: print] | |
console.log(boundPrint); // => [Function] | |
boundPrint(); // => All the data. | |
// Example | |
$("li").click(function(e){ | |
// this === li | |
// turns into | |
// this === config | |
}.bind(config)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment