Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created December 28, 2013 08:50
Show Gist options
  • Save lyuehh/8157456 to your computer and use it in GitHub Desktop.
Save lyuehh/8157456 to your computer and use it in GitHub Desktop.
console.log('1:');
(function() {
console.log(add(1, 2));
function add(a, b) {
return a + b;
}
})();
console.log('2:');
(function() {
//console.log(add(1, 2)); // ERROR
var add = function (a, b) {
return a + b;
};
})();
console.log('3:');
a = 'a';
var o = {a: 'b'};
function showA() {
console.log(this.a);
}
showA();
o.showA = showA;
o.showA();
console.log('4:');
function add(a, b) {
return a + b;
}
console.log(add.name);
console.log(add.length);
console.log('5:');
a = 'a';
var o = {a: 'b'};
function showA() {
console.log(this.a);
}
showA.call(this); // different in node and browser
showA.call(o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment