什么是JavaScript call()方法?
JavaScriptcall()方法用于以另一个对象作为第一个参数的函数。
示例
您可以尝试运行以下代码以了解如何call()
在JavaScript中实现方法-
<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>