什么是JavaScript call()方法
JavaScript call()方法是用来调用一个以另一个对象为第一参数的函数。
示例
你可以尝试运行以下代码来学习如何在JavaScript中实现call()方法 —
<html>
<head>
<script>
var person = {
Name:"John",
Department: "Finance",
fullName: function() {
return this.Name + " is from " + this.Department + " Department";
}
}
var myObject = {
Name: "Amit",
Department: "Marketing",
}
x = person.fullName.call(myObject);
document.write(x);
</script>
</head>
<body>
</body>
</html>