函数apply和call的简单例子

来源:互联网 发布:怎么阅读安卓源码 编辑:程序博客网 时间:2024/06/06 17:42

Function.apply and Function.call in JavaScript

The apply() method is identical to call(), except apply() requires an array as the second parameter. The array represents the arguments for the target method.

<html><head><script>function zou() {var x = 10;var o = {x : 15};function f(message) {alert(message);alert(this.x);}f("invoking f");f.call(o, "invoking f via call");}</script><title>test</title><body>   <a href="javascript:zou()">Let's go!</a>   </body></html>

原文:http://odetocode.com/blogs/scott/archive/2007/07/05/function-apply-and-function-call-in-javascript.aspx


原创粉丝点击