I changed a bug yesterday. The property name is repeated, which leads to a very interesting little bug. The result of a bug is the code of a JS object declaration, which is equivalent in structure to the following code.
var fn = function () {" use strict ' ; var obj = {A: 1 , A: 2 // Because the declared property is more, the property added later is accidentally repeated with the existing property }; return obj};fn ();
At that time, I tested the program in the chrome of the PC, ran it, and tested it on the Android, no problem. But in the iphone, but the error, resulting in the page does not render properly. It is easy to locate the wrong code by using Safari to connect to the phone and find this interesting problem: The strict mode has different processing strategies for repeating attributes in different JS running environments . Let's take a look at the execution of this code in each of the operating environments
- Chrome
- Safari
- Firefox
- Nodejs
From the above experimental results can be seen, even in strict mode, the various operating environment to the partial details of the processing is not the same. In strict mode, Safari and Nodejs object literals prohibit duplicate attribute declarations, while Chrome and Firefox do not have this limitation. The same scripting engine that chrome and Nodejs supposedly use should be consistent, and the difference is a bit of a hassle. So even if the code running in strict mode is not 100% insured, it is necessary to do more testing .
The difference of use strict to duplicate attribute processing in different JS environments