当前位置: 代码迷 >> JavaScript >> 请教Prototype中的Class类中的apply用发是什么意思
  详细解决方案

请教Prototype中的Class类中的apply用发是什么意思

热度:107   发布时间:2012-03-09 21:42:52.0
请问Prototype中的Class类中的apply用发是什么意思?
var   Class   =   {
    create:   function()   {
        return   function()   {
            this.initialize.apply(this,   arguments);
        }
    }
};
var   vehicle=Class.create();

vehicle.prototype={
        initialize:function(type){
                this.type=type;
        },
        showSelf:function(){
                alert( "this   vehicle   is   "+this.type);
        }
}

var   moto=new   vehicle( "Moto ");
moto.showSelf();

其中this.initialize.apply(this,   arguments);在什么时候运行,此处的this是哪个对象?

------解决方案--------------------
在 var moto=new vehicle( "Moto ");的时候运行
this指的是 Class()
  相关解决方案