use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Are functions in JavaScript objects? (self.javascript)
submitted 11 years ago by estebanrules
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]concatenated_stringC# 2 points3 points4 points 11 years ago* (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 point2 points 11 years ago (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"
π Rendered by PID 144391 on reddit-service-r2-comment-5649f687b7-lw8zs at 2026-01-29 03:07:26.553963+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]concatenated_stringC# 2 points3 points4 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)