JavaScript Succinctly 读后笔记
1.JavaScript does not have block scope
2.Scope is determined during function definintion, not invocation -- Closoure
3.Replacing the prototype property with new Object removes the default constructor property
4. the default return value of new constructor is this.
var Person = function(){
this.name = "andy";
// return this;
}
console.log(new Person().name); // output: andy
5. some usful functions
function existy(x) { return x != null };
test case for existy -- JavaScript only has two values -- null and undefined that signify nonexistence
existy(null);
//=> false
existy(undefined);
//=> false
existy({}.notHere);
//=> false
existy((function(){})());
//=> false
existy(0);
//=> true
existy(false);
//=> true
The use of existy
=================
function truthy(x) { return (x !== false) && existy(x) };
test cases for truthy
truthy(false);
//=> false
truthy(undefined);
//=> false
truthy(0);
//=> true
truthy('');
//=> true

浙公网安备 33010602011771号