01 2012 档案
摘要:call() 方法它的第一个参数用作this的对象,其他参数都直接传递给函数自身;重写上个例子:function ClassA(sColor){ this.color = sColor; this.sayColor = function(){ alert(this.color) }};function ClassB(sColor,sName){ ClassA.call(this,sColor)//这里的this 是指ClassB this.name = sName; this.sayName = function(){ a...
阅读全文
摘要:面向对象语言 必须支持继承机制,既一个类能重用另一个类的方法和属性.1、继承方式对象冒充工作原理:构造函数使用this关键字,给所有属性和方法赋值,因为构造函数值只是一个函数,所以可以使ClassA的构造函数成为ClassB的方法 。然后调用它,ClassB就会收到ClassA的构造函数中定义的属性和方法。考虑下面例子function ClassA(sColor){ this.color = sColor; this.sayColor = function(){ alert(this.color) }};function ClassB(sColor){ t...
阅读全文