Last active
August 29, 2015 14:17
-
-
Save kj786/f7ef2163738d2a37ea86 to your computer and use it in GitHub Desktop.
What is practical difference between String(...) and new String(...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I failed to properly understand the way String(..) works in following portion: | |
return new TextCell(String(row[name])); | |
from http://eloquentjavascript.net/06_object.html | |
The answer is below https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String: | |
Distinction between string primitives and String objects | |
Note that JavaScript distinguishes between String objects and primitive string values. (The same is true of Boolean and Numbers.) | |
String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the new keyword) are primitive strings. JavaScript automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup. | |
http://stackoverflow.com/questions/3945202/whats-the-difference-between-stringvalue-vs-value-tostring | |
http://www.adequatelygood.com/Object-to-Primitive-Conversions-in-JavaScript.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment