Skip to content

Instantly share code, notes, and snippets.

@jiukunz
Last active August 29, 2015 13:57
Show Gist options
  • Save jiukunz/9487193 to your computer and use it in GitHub Desktop.
Save jiukunz/9487193 to your computer and use it in GitHub Desktop.

JavaScript是一个类型无关(class-free),面向对象的语言,使用的时原型集成方式而非经典的类继承方式。

为什么要说继承呢? 有两个原因:

  1. Javascript是一种弱类型的语言。弱类型语言有个好处,就是对象之间转换比较容易。要知道,在强类型语言中(比如Java),对象如果没有继承关系,那么是不能相互转换的。但在javascript中,所关心的只是对象中有没有我想要调用的方法,想要获取的属性,只要你张的像鸭子,那我就认为你是个鸭子(Duck typing),这就可以很方便的将对象作为参数在函数中传来传去,而不用在意函数想要接受的参数类型。

###constructor ###new ###prototype ###this

reference: 1.http://www.crockford.com/javascript/inheritance.html 2.http://blog.sina.com.cn/s/blog_65d26f050100npt6.html 3.http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript 4.http://pivotallabs.com/javascript-constructors-prototypes-and-the-new-keyword/ 5.http://www.w3school.com.cn/jsref/jsref_constructor_array.asp 6.http://blog.csdn.net/hikvision_java_gyh/article/details/8937157 7.http://www.cnblogs.com/phpmix/articles/1734031.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment