call()的具体使用方法

先展示个例子: 

    var Person = function(name){
		this.name = name;
	};

	Person.prototype = {
		constructor:Person,
		id:100
	};
	var Boy = function(name,sex,age){
		Person.call(this,name);
		this.sex = sex;
		this.age = age;
	};

详解:call()是将Person的属性绑定到当前(this也就是Boy)方法中,让其拥有相同的属性;

语法:

     fun.call(thisArg, arg1, arg2, ...)

猜你喜欢

转载自blog.csdn.net/weixin_41530824/article/details/84839371
今日推荐