js中的call和 apply
<!DOCTYPE html
>
<html
>
<head
>
<meta charset
="UTF-8">
<title
>call和 apply
</title
>
<script type
="text/javascript">
function Person(name
, age
, gender
){
this.name
= name
;
this.age
= age
;
this.gender
= gender
;
this.sayName = function(){
console
.log(this.name
);
};
}
var obj
= new Person("name",12,"女");
function fun(a
,b
){
console
.log(a
);
console
.log(b
);
}
fun
.call(obj
,1,2);
fun
.apply(obj
,[1,2])
</script
>
</head
>
<body
>
</body
>
</html
>
转载请注明原文地址: https://lol.8miu.com/read-16142.html