学习了ECMAscript的call和apply方法

参考链接http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp  
//对象冒充
	function classA (color){
		this.color = color;
		this.sayColor = function(){
			console.log(color);
		};
		this.sayOnther = function(){
			console.log(color+"2")
		};
	}
	function classB (color,name){
		this.syaColor = classA;
		this.syaColor(color);

		delete this.newMethod;

		this.name = name;
		this.sayName = function(){
			console.log(name);
		};
	}
	var a = new classA("red");
	var b = new classB("blue","noin");
	//a.sayColor();
	//b.sayColor();
	//b.sayName();
	//call()方法与apply()效果一样
	function classC(color,name){
		classA.call(this,color);//call方法
		//classA.apply(this,new Array(color));//apply方法
	}
	var c = new classC("yellow","noin");
	c.sayColor();
	c.sayOnther();

你可能感兴趣的:(学习了ECMAscript的call和apply方法)