When I use the String constructor I allways wonder how is it made.It returns the string you specificed as a parameter even though it is instanciated with the "new" operator like :
var str = new String("Hello World")
//str == "Hello World"
If I make a constructor and I give it a return value it returns an Object when instanciated :
function CreateString(st) {
return ''+st
}
var MyString = new CreateString("Hello there!")
//MyString == "[Object object]"
How can I create a constructor that returns a value Other than [Object object] ?
Update: I am trying to create a constructor function that has both properties and a value itself like :
function MyConstructor() {
this.myMethod = function() {
return 73
}
return 25
}
/*I want MyConstructor to have the value 25 and the myMethod method */
alert(MyConstructor()) // to be 25
alert(MyConstructor().myMethod()) //to be 73