听课笔记-Douglas Crockford JavaScript Programming 3,4


The JavaScript Programming Language(3)
http://video.yahoo.com/watch/111595/1710607

The JavaScript Programming Language(4)
http://video.yahoo.com/watch/111596/1710658


1. function are first-class object


2.function foo(){} == var foo=function (){}


3.static scope ,lexical scope


4.closure : the scope that an inner function continues even after the parent functions have returned


5.every function call has a scope


6.method : function stored into object


7.four ways to call function


    7.1 function form     f(arguments)  this == global object


    7.2 method form     o.f(arguments)   this ==o


    7.3 constructor form     new f(arguments)   this == new object created


    7.4 apply form        f.apply(o,[arguments])   this ==o


8.this is bound of invocation time.


9.arguments


     9.1  调用时自动出现在该函数作用于内


      9.2 an array-like object


     9.3 length 属性 是指实际调用参数的个数


10. can argument(expand) built-in types


  

String.prototype.trim = function () {


             return this.replace(/^\s*\S*(\s+\S+)*\s*$/,'$1');


   } 

 

PS:

 

    最快的trim:  (From Steven Levithan )

 

String.prototype.trim = function (){ 
    var text = this.replace(/^\s+/, ""); 
    for (var i = text.length - 1; i >= 0; i--) { 
        if (/\S/.test(text.charAt(i))) { 
            text = text.substring(0, i + 1); 
            break; 
        } 
    } 
    return text; 
} 

 

好用简洁的trim :

 

String.prototype.trim = function (){ 
    return this.replace(/^\s+/, "").replace(/\s+$/, ""); 
} 
 

 

 

   but in java String is final ,can not be expanded


11.           


type          typeof


object           'object'

function          'function'

array           'object'

number           'number'

String           'string'

object           'object'

boolean           'boolean'

null                  'object'

undefined          'undefined'



12. eval () 不建议使用  ,除了 JSON 解析


13  avoid  new Boolean()  new Number() new String()


       new Boolean(false)  truthy


14   on browser  global object == this


window.document ==document 白白多了一层自己查看


15 .尽量不要用全局变量 ,避免冲突 ,用 对象来管理你的命名空间


16 .使用匿名函数来达到封装的目的


 var application = (function () {


    var x='';


     return function () {


                 // 对 x 的 使用 在此


       }



})();



你可能感兴趣的:(JavaScript,json,prototype,Yahoo,F#)