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:

Comments
Post a Comment