IE8错误将函数()分配给属性名称'function'

Vik*_*ram 0 javascript google-chrome internet-explorer-8

考虑在IE8和Chrome控制台中运行以下代码进行比较:

var a = function(){ console.log("function is() initialized"); };

// assign a property named 'function' to function 'a'

a.function = function afunction(f){ return (typeof f === 'function'? true: false); };

// Use our is function to test if a given variable is a function

a.function(a); // IE throws 'expected identifier' error v/s Chrome correctly outputs "true"
Run Code Online (Sandbox Code Playgroud)

任何想法如何在IE8中解决这个问题而不改变函数签名:a.function()?

Jon*_*Jon 5

使用备用属性访问语法,该语法不受保留字的干扰:

a["function"](a);
Run Code Online (Sandbox Code Playgroud)