Differences in browser Implementation of function call in ES3 and es5.

Source: Internet
Author: User

It's similar to the following:Code:

Reference code:

 
VaR o = {test: function () {alert ('origin') }}; O. test (O. test = function () {alert ('changed ');});

In this Code, we intuitively think that printing the origin is reasonable. At least I personally think so.

But. chrome17-and IE8-both print changed. While firefox0.8 +, safai3 +, opera9.2 +, and ie9 + both print origin.

 

The root cause of this problem can be found by looking at ES3 and es5. ES3 and es5 are in conflict here. douglas thinks ES3 is unreasonable. so the logic here is changed.

ES3:

Function CILS
The production callexpression: memberexpression arguments is evaluated as follows:
1. Evaluate memberexpression.
2. Evaluate arguments, producing an internal list of argument values (see 11.2.4 ).
3. Call getvalue (Result (1 )).

 

Es5:

11.2.3 function CILS
The production callexpression: memberexpression arguments is evaluated as follows:

1. Let ref be the result of evaluating memberexpression.
2. Let func be getvalue (REF ).
3. Let Arglist be the result of evaluating arguments, producing an internal list of argument values (see 11.2.4 ).

 

Visible es5 PairsMemberexpressionThat is, the reference obtained by the expression in the function name section. The getvalue operation is performed before the evalute operation on the real parameter list.

ES3 is the opposite.

 

From a historical perspective, let's look at the problem. Right or wrong?

. Firefox4 began to implement the engine in accordance with the es5 standard. Then, the Firefox 3.6-browser did not comply with the current ES3 standard.

. Opera11.6 is implemented in accordance with es5. Therefore, opera11.5-'s browser is the same as ff3.6-and does not comply with es3.

The same is true for Safari3-5. Under the premise that safari5.11 is still very supportive of es5, it has never followed es3.

. Chrome has partially supported es5 APIs since version 5 and has been fully implemented by es5 since version 11. but until Version 17. it is still implemented according to es3. obviously, it is incorrect.

 

From the historical point of view, the best thing is that the IE series. IE system implements the JScript engine according to es5 from 9th. The result is perfect in this regard. IE8-implemented by ES3. ie9 + implemented by es5.

 

This time, ie is worthy of praise! A small red flower.

 

 

 

Finally, let's talk about the strange settings of ES3.

For newNewexpression

There is no such problem at all. It is also consistent with es5.

That is, first evaluteNewexpression, And then getvalue, and then go to evaluteArguments

Reference code:

 
VaR cons = function () {This. name = 1 ;}; var OBJ = new cons (cons = function () {This. name = 2;}); alert (obj. name)

There will be no difference in the implementation of all browsers, because there is no difference between ES3 and 5. Why is function call so strange? For the time being, I still cannot figure out the reason for this design.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.