【问题标题】:IE8 error assigning a function() to a property name 'function'将函数()分配给属性名称“函数”的 IE8 错误
【发布时间】:2014-08-26 22:20:10
【问题描述】:

考虑在 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"

任何想法如何在不更改函数签名的情况下在 IE8 中解决此问题:a.function()?

【问题讨论】:

    标签: javascript google-chrome internet-explorer-8


    【解决方案1】:

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

    a["function"](a);
    

    【讨论】:

    • 我提出了一个后续问题here。感谢您的宝贵时间!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 2016-01-15
    相关资源
    最近更新 更多