Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JavaScript function a "function" or an "object" or both?

Tags:

javascript

I am trying to get my head around how Javascript function behaves. Is it a function or an object or both?

like image 328
rkg Avatar asked Oct 15 '10 16:10

rkg


1 Answers

Functions in javascript are first-class objects. So they're both functions and objects.

Because they are first class objects, you can assign a variable to a function and give it properties, eg:

var addName=function(){}; 
addName.blah = 1;

If they weren't first-class objects you'd be limited to this syntax but you can do it both ways:

function addName(){}
like image 112
meder omuraliev Avatar answered Dec 02 '22 15:12

meder omuraliev