Saturday, June 29, 2019

Difference between JavaScript Engines

Spread operator

JavaScriptCore the JavaScript engine in SAFARI Mac Os and iOS as well as in Chrome iOS implements the spread operator differently than V8 (Chrome) or Spider Monkey (Firefox).


o1 = { id1:{ isSelected: false}, id2:{ isSelected: false}, id3:{ isSelected: false} }
selected = { id2:{ isSelected: true} }
r = {...o1, ...selected}

// Chrome Windows, FireFox Windows, Chrome MacOs
// The order of the key/property is preserved based on variable o1
{ id1:{ isSelected: false}, id2:{ isSelected: true}, id3:{ isSelected: false} }

// Safari Mac, Safari iOS, Chrome iOS
// The order of the key/property is NOT preserved based on variable o1
// The key/property id2 is now at the end
{ id1:{ isSelected: false}, id3:{ isSelected: false}, id2:{ isSelected: true}  }


This is not a bug, as you should not assume the order of the key/property in an dictionary or object.

Issue sorting array of objects in different browser 

Chrome and Firefix Windows will not return the same result.

No comments:

Post a Comment