Instead of string it is object
String.prototype.foo = function () { return this; };
typeof "hello".foo() // object ???
"hello".foo().toString(); //hello
it should return string instead i guess.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. A real string (
"hello",'booya') is a primitive value – it doesn’t have any functions or anything. It’s just a value.When you do
"string".foo, it turns into this:Inside of
foo,thispoints towardsObject("string"), not the primitive value. DoingObject("string")turns it into an object, sotypeof object === 'object'.If you want the “underlying” primitive, call
valueOf: