Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

JavaScript - Functions as objects

The concept of functions being objects in JavaScript would be ok with me if I could understand the following question. I have searched around and looked into the javascript engine to try and find the answer, but no explanation I've found so far sits well in my mind...

An object like the one below is understandably layed out in a hash map type of construct.

var person = {
 firstName:"John",
 lastName:"Doe",
 age:50,
 eyeColor:"blue"
};

However, to say this is also an object is where I get stuck:

var name = function () {
 alert ('name');
}
  1. In terms of memory, how is this function stored?

  2. Are the statements inside the "hash map" of a function layed out in an execute order? So each property is called upon after the other?

I'm probably missing something or visualising something wrong.

Thanks.

P.S

To clear up question 2,

Say I have an if statement inside my function... will that be stored in a property accessible through one of its properties?

Answer*

Draft saved
Draft discarded
Cancel
1
  • Sorry, hopefully this clears up my question - say I have an if statement inside my function... will that be stored in a property accessible through one of its properties? Commented Mar 3, 2016 at 1:47

lang-js

AltStyle によって変換されたページ (->オリジナル) /