Last active
February 9, 2017 23:27
-
-
Save liqiang372/2e69338e5b025211e00d6267944e9a63 to your computer and use it in GitHub Desktop.
for enhui study
This file contains hidden or 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 x = 1; | |
console.log("whatever") |
This file contains hidden or 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
// The "this" keyword in JavaScript | |
window.name = "shenmegui"; | |
var fruits = { | |
name: "fruits", | |
color: "nocolor", | |
eat: function() { | |
console.log("eating " + this.name); | |
} | |
} | |
fruits.eat(); // eating fruits; | |
var x = fruits.eat; | |
x(); // eating shenmegui | |
x.bind(fruits)(); // eating fruits; | |
// call and apply | |
function addAndSetX(a, b) { | |
this.x += a + b; | |
} | |
var obj = {x : 1}; | |
addAndSetX.call(obj1, 1, 1); // this = obj1, obj = { x : 3} | |
addAndSetX.apply(obj1, [1, 2]); // this = obj1, obj = { x : 6} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment