1582Re: [jslint] Re: ES5 and constructors
- Nov 9, 2010A good exemple
var s = String(3); // typeof s === "string"
var s = new String(3); // typeof s === "object"
String() can be used to convert any value into a string while new String() will create an object which constructor is String and which toString method will return its conversion into a string value.
In ES5 strict mode, without new, when not applied as a method on an object, the value of this can null or undefined
You can never say for sure that a function won't be used as a constructor
You just have some little tricks like...
- the function has been called once with new (then you are quite sure)
- a property has been defined on its prototype (useless on other function than constructors)
- its first letter is upper case (convention only)
- it has a JSDoc with the tag "@constructor" (the developers probably wants you to manage it as a constructor)
- it is a standard builtin constructor (from JS Core, DOM, BOM, ...)
>[Non-text portions of this message have been removed]
- << Previous post in topic