前言 这一章的内容是 advanced knowledge and use of functions. 讲了关于 function 的使用的一些特殊的方面. function expression 的定义 格式: var fly = function(num){for(var i = 0; i < num; i++) {console.log("Flying!");}}; fly(3); 与 function declaration 的两个不同之处 runtime 不同:func…
When you invoke the constructor function with new, the following happens inside the function: • An empty object is created and referenced by this variable, inheriting the prototype of the function. • Properties and methods are added to the object ref…
What are the benefits to using anonymous functions instead of named functions for callbacks and parameters in JavaScript event code? I use anonymous functions for three reasons: If no name is needed because the function is only ever called in one pl…
Objects Object Usage and Properties Everything in JavaScript acts like an object, with the only two exceptions being null and undefined. false.toString(); // 'false' [1, 2, 3].toString(); // '1,2,3' function Foo(){} Foo.bar = 1; Foo.bar; A common mis…
What Makes Javascript Weird...and AWESOME -> First Class Functions -> Event-Driven Evironment -> Closures -> Scope -> Context scope === variable access context === this First Class functions(回调函数) function add(first,second,callback){ consol…