首页 > 代码库 > Java Script after Douglas Crockford's Training (JSON father)

Java Script after Douglas Crockford's Training (JSON father)

有幸能参加大牛的培训,学到了很多东西,下面总结一下:

1.总的思想是每一门语言都有好有坏,我们要通过好的代码规范和其他一些方式去避免使用糟糠的那一部分。JS有很多缺点,但是也有很多优点,我们就用他的优点就够了,不要去把他的缺点的部分加到你的代码里

2.每一个Object 就是一个动态属性的集合。Object里每个属性都有一个唯一的Key。可以看作是HashMap

3.JS中所有都是对象除了(null and undefined)

创建对象的方式:

•var my_object = {foo: bar};

•var my_object = Object.defineProperties(

        Object.create(Object.prototype), {

    foo: {

        value: bar,

        writeable: true,

        enumerable: true,

        configurable: true

    }

});

4.获得一个Object的attribute有两种方式(类似 set and delete)

•get

object.name 

object[expression](这种方式避免使用,防止注入攻击)

•set

object.name = value; 

object[expression] = value;

•delete

delete object.name

delete object[expression]

5.prototypes

•可以创建一个你想要的Object

•可以继承其他对象

•Customize 自己的对象

6.JS里面的类型(除了Object)

•Number(数字类型,没有Int ,long double,etc)
•Boolean
•String
•Array
•Date
•RegExp
•Function

7.分清楚== 和=== 的区别,推荐是用===

 

8.NaN

•不是数字

•是undefined 或者 erroneous 的 运行结果

•NaN equals nothing

•NaN === NaN is false
•NaN !== NaN is true

9.Arrays

•Array inherits from Object.
•Indexes are converted to strings and used as names for retrieving values.
•Very efficient for sparse arrays.
•Not very efficient in most other cases.
•One advantage: No need to provide a length or type when creating an array.

 

。。。。。。待续

Java Script after Douglas Crockford's Training (JSON father)