I’m still learning JavaScript,reading books,utilizing FireBug,experimenting.
I’m amazed and stuck on thing below.
Have function declaration:
var t = function (args){
...
}
It’s assumed,that it’s varargs.
I call it like:
<body onload="t({to:100,from:0})">
It’s possible to get from argument value by calling:
args.from
The result of typeof args.from is number
That looks sane.
pay attention: number is in lower case
I am interested of what instance args.from is.
Actually, can’t get its instance value.
tried:
args.from instanceof Number
args.from instanceof String
args.from instanceof Object
args.from instanceof Boolean
It is not Number – very strange
It’s not Object – quite strange
It’s not String -that’s OK
It ‘s not Boolean -that’s OK
It’s neither null nor 'undefined' – looks OK.
What is it?
That’s a primitive numeric value.
It isn’t an instance of any class.
instanceofcan only return true on objects (for whichtypeofreturns"object"or"function").This has nothing to do with the
argsobject; you can get the same falsity from4 instanceof Number.By contrast,
new Number(4)is an object wrapping the primitive4, sotypeof new Number(4) === "objectandnew Number(4) instanceof Number === true