简体   繁体   English

Javascript函数作为参数-浏览器兼容性

[英]Javascript function as parameter - Browser compatibility

I know that the ability to pass function names as parameters is handled by almost all modern browsers, but I'm wondering about older browsers compatibility: 我知道几乎所有现代浏览器都可以处理将函数名作为参数传递的功能 ,但是我想知道旧版浏览器的兼容性:

  1. What was the first version of JavaScript/ECMAScript that supported it? 支持它的JavaScript / ECMAScript的第一个版本是什么? Was it supported since the first days of JavaScript? 从JavaScript的第一天开始支持它吗? (That would surprise me) (这会让我感到惊讶)
  2. What were the versions of each of the major browsers (Google Chrome, Firefox, IE, Safari, Opera, etc.) that first supported it? 首先支持它的每种主要浏览器(谷歌浏览器,Firefox,IE,Safari,Opera等)的版本是什么?

据我所知,函数始终是对象,并且对象始终可以作为参数传递。

The use of anonymous functions as expressions and the passing of the names of declared functions has been available on all JavaScript supporting browsers since before Internet Explorer 6. 自Internet Explorer 6之前,所有支持JavaScript的浏览器都可以使用匿名函数作为表达式并传递声明的函数的名称。

The first documentation I could find on it is ECMA-262 , which dates as far back as 1997. 我可以找到的第一份文档是ECMA-262 ,其历史可以追溯到1997年。

If you're talking about full support, old versions of IE ( even up to IE8 ), suffered from a variable leak in named function expressions , where the name of the function expression becomes defined and set in the parent scope, as if it was actually a declared function . 如果要讨论全面支持,则旧版本的IE( 甚至是IE8之前的版本 )在命名函数表达式中会发生变量泄漏,在该函数表达式中 ,定义了函数表达式名称并在父作用域中进行了设置,就好像它是实际上是一个声明的函数

// Assuming old JScript engine
typeof foo; // "undefined", expected, it's not been defined yet
bar; // defined as if hoisted function declaration, unexpected

var foo = function bar() {};
foo; // as expected
bar; // identical to foo, not expected

foo === bar; // false, they're actually different function objects in memory

What was the first version of JavaScript/ECMAScript that supported it? 支持它的JavaScript / ECMAScript的第一个版本是什么? Was it supported since the first days of JavaScript? 从JavaScript的第一天开始支持它吗? (That would surprise me) (这会让我感到惊讶)

1 1个

It is a core language feature. 这是核心语言功能。

What were the versions of each of the major browsers (Google Chrome, Firefox, IE, Safari, Opera, etc.) that first supported it? 首先支持它的每种主要浏览器(谷歌浏览器,Firefox,IE,Safari,Opera等)的版本是什么?

The earliest JS supporting browsers support it. 最早的JS支持浏览器支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM