jshint/jshint — Issue #392: Allow Object() called as function, not constructor
Author: inexorabletash
Created: 2011-12-22 05:10:59+00:00
State: open

Currently, this construct:

var y = "hello";
var x = Object(y);

Produces:

"Missing 'new' prefix when invoking a constructor."

Like Boolean, Number, and String, Object can be called as a function, which provides scripts with access to ECMAScript's internal ToObject logic. If passed an object, return it. If passed a primitive, return a new Number, Boolean, or String as appropriate (or new Object for null/undefined). This is useful primarily when implementing shims for new ECMAScript functionality that is specified to use the ToObject internal method.

Hiding this behind an option would be acceptable.