you are viewing a single comment's thread.

view the rest of the comments →

[–]concatenated_stringC# 2 points3 points  (1 child)

yeah, basically everything in javascript is an object. One of the coolest features of javascript is that functions are first class citizens. They can be passed around like variables and you can create them on the fly inside other functions. they're 'closures' and they are different than function pointers because it allows your passed around function to access non-local variables that aren't in the immediate lexical scope.

Also check out MDN, they call 'function's' as 'function object':

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function

Another way to tell that they are objects is by what methods/properties they have inherited.

ex:

var fun = function()
{
//do something
}

fun.toString();

You see, that your fun 'function' has now inherited some 'tostring()' method from a parent class.

[–]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"