Skip to content

literals-and-constructors/primitive-wrappers.html #22

Closed
bitsofpancake opened this Issue Jan 17, 2012 · 0 comments

2 participants

@bitsofpancake

The last example on literals-and-constructors/primitive-wrappers.html is commented incorrectly:

// primitive string
var greet = new String("Hello there");
// primitive is converted to an object
// in order to use the split() method
greet.split(' ')[0]; // "Hello"
// attemting to augment a primitive is not an error
greet.smile = true;
// but it doesn't actually work
console.log(typeof greet.smile); // "boolean"

It should be:

// string with wrapper
var greet = new String("Hello there");
// object has split() method
greet.split(' ')[0]; // "Hello"
// augmenting object
greet.smile = true;
console.log(typeof greet.smile); // "boolean"
@shichuan shichuan closed this in 35d8f10 Apr 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.