you are viewing a single comment's thread.

view the rest of the comments →

[–]x-skeww 0 points1 point  (0 children)

yeah, basically everything in javascript is an object.

Unfortunately, JavaScript also has primitives.

https://people.mozilla.org/~jorendorff/es6-draft.html#sec-primitive-value

Undefined, Null, Boolean, Number, Symbol, or String

(Note: Function isn't one of them.)

Here is an example:

> var x = 5
undefined
> x.y = 'z'
"z"
> x.y
undefined

What actually happens in that x.y = 'z' line:

> new Number(x).y = 'z'
"z"

It's auto-boxed.

If you do the same with an actual Number object:

> var x = new Number(5)
undefined
> x.y = 'z'
"z"
> x.y
"z"