js 库中常见的 prototype 是干什么的?

在 js 库中,经常能够看见 prototype 的使用,目的是对原来的对象进行扩充,

比如:

String.prototype.hello, 这里给String 对象扩充了一个 hello属性。这样将来所有 string都有了该属性。

Array.prototype.sayHello() = function(){}

所有 Array 都有了一个 sayHello() 方法

 

posted @ 2012-08-08 07:47  allenbackpacker  阅读(351)  评论(0编辑  收藏  举报