javascript - Why does jslint prefer {}.constructor(obj) over Object(obj) -


both detect objects , not primitives.

it seems purely syntactical difference.

// jslint prefers {}.constructor(obj) on object(obj) // called isobject underscore // test objects have writable keys // example string literals not detected // arrays var iswritable = function (obj) {     return {}.constructor(obj) === obj; }; 

i'm not quite sure, shouldn't. if you're looking @ performance, that's opposite of should doing.

according this jsperf test available compares speed of creating via new object(), object.create().new(), , object.prototype.constructor() (which same object.constructor()); object.constructor() slowest 1 of them all far.

google's v8 engine magnitudes faster using new object() because optimizes call heavily, wouldn't worry it.

results jsperf test:

operation per second comparison of object creation functions the graph results of speed of different object creation functions in multiple browsers


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -