call、apply和bind() 三种是比较常用的方法,用来改变一些函数方法内部this指向
call
call()方法 调用一个对象,简单理解为调用函数的方式,但是它可以改变函数的this指向
fun.call (thisArg, arg1,arg2,arg3,…)
主要作用:
- 可以调用函数
- 可以改变函数内this指向
- 主要用于继承
主要应用:继承
<script>
function Father(uname,num,price) {
this.uname = uname;
this.num = num;
this.price = price;
}
function Son(uname,num,price) {
Father.call(this,uname,num,price);