IE8错误将函数()分配给属性名称“function” [英] IE8 error assigning a function() to a property name 'function'

查看:132
本文介绍了IE8错误将函数()分配给属性名称“function”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

//将一个名为'function'的属性赋值给函数'a'

a.function = function afunction(f){return(typeof f ==='function' ? 真假); };

//使用我们的函数来测试一个给定的变量是否是一个函数

a.function(a); // IE抛出'expected identifier'错误v / s Chrome正确输出true

这可以在IE8中解决,而不会改变函数签名:a.function()?

不受保留字的干扰:

  a [function](a); 


Consider running the following code in IE8 and Chrome consoles to compare:

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"

Any ideas how this can be tackled in IE8 without changing function signature: a.function()?

解决方案

Use the alternate property access syntax, which is immune to interference from reserved words:

a["function"](a);

这篇关于IE8错误将函数()分配给属性名称“function”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆