Function.prototype.make=function(n,f) {
this.prototype[n]=f ;
}
A是函数,Function.prototype是所有函数的原型。
// 这里的this指向构造函数:
var A=function( ) { }
A.make=function(n.f) {
this.prototype[n]=f; // A.prototype 这里指向原型
}
var Box=function( ){ }
Box.make("set",function(x){
this.x=x;
})
Box.make("get",function(x){
this.x=x;
})
该写法,相当于:
Function.prototype["set"]=function(x){
this.x=x;
}
这其实是Json的写法:
Function.prototype={
"set":function(x){
this.x=x;
}
}
================================
var A=function( ){ }
A.prototype.make=function( ){
alert(this==A.prototype);
}
A.prototype.make( );
结果返回true。
=============================================================
<script type="text/javascript">
function a( ) {
var m=10;
}
a.prototype.mm="sda";
var ab=new a( );
alert(a.prototype.constructor==a) // 结果为true