//面向对象 属性定义在构造函数中,方法定义在原型中 function Animal(name){ this.name = name; this.type = "dog"; //this 指向的是公有属性 var age = "10"; //私有属性 } Animal.prototype = { say:function(){ alert("this is a "+ this.type + ","+ this.name); } } //继承 function Bird(name){ Animal.call(this,name); } // Bird.prototype = Animal.prototype; //使用内存地址赋值 Bird.prototype = new Animal(); Bird.prototype.constructor = Bird; //将Bird的构造函数重新指向自己 Bird.prototype.fly = function(){ alert("i am fly"); } var dog = new Bird("wangcai"); dog.fly(); js call和apply的区别:func1.call(this, arg1, arg2); func1.apply(this, [arg1, arg2]);