Why is it possible to store a function of the prototype inside a variable?

Sven

To improve my understanding of JavaScript, I started to read other people's source code. On Github, I encountered a script that has this variable declaration at the top:

var has = Object.prototype.hasOwnProperty;

Later in the code it's used like this:

if (has.call(params, key)) {  
    // stuff
}

How does this even work? Effectively, has is now some kind of alias for Object.prototype.hasOwnProperty, but why is it possible to store a prototype method in a variable – since it's now a function call, there isn't anything returned.

Lazarus

A function is a first class citizen in Javascript (as is the case in some other languages as well) that means they can be assigned to variables, passed as arguments to other functions as well as returned from functions. There's a good piece on first class functions on Wikipedia: https://en.wikipedia.org/wiki/First-class_function

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Assigning prototype methods *inside* the constructor function - why not?

From Dev

Why is it possible to define a variable inside a loop in C?

From Dev

Is possible change operator = by a variable inside a function POSTGRESQL?

From Dev

Why can't I assign a function to a variable using prototype?

From Dev

Why my variable is undefined inside the function

From Dev

Why is global variable readable, but not writeable inside a function?

From Dev

prototype method is not a function,why?

From Dev

Why is it possible to store more than one characters in a "char" variable?

From Dev

Is it better to store array in a variable or directly pass an array to a function inside a loop?

From Dev

Is it better to store array in a variable or directly pass an array to a function inside a loop?

From Dev

require function inside or outside of prototype?

From Dev

'this' inside each function in Prototype JS

From Dev

require function inside or outside of prototype?

From Dev

Calling a function listed inside a prototype

From Dev

Accessing "this" in Function.prototype not possible?

From Dev

Why is the function argument not overwritten on creating variable of same name inside the function?

From Dev

Why am I unable to declare a variable inside a function with a nested function?

From Dev

Store function inside an array

From Dev

Store function inside an array

From Dev

Why is it not possible to access other variables from inside the apply function in Python?

From Dev

Why isn't .forEach() working inside Array.prototype.fillB()? (a custom function)

From Dev

Why does JavaScript let you store an array and a function in one variable?

From Dev

Why store the result of getElementById() to a variable instead of using the function everytime?

From Dev

Why use "[*]" instead of "[]" in function prototype?

From Dev

Javascript: Why array variable assignment is behaving differently inside and outside this function?

From Dev

Why doesn't use the variable value inside the function in python

From Dev

Python - Store function in variable

From Dev

Store function result into variable

From Dev

Store function result into variable

Related Related

  1. 1

    Assigning prototype methods *inside* the constructor function - why not?

  2. 2

    Why is it possible to define a variable inside a loop in C?

  3. 3

    Is possible change operator = by a variable inside a function POSTGRESQL?

  4. 4

    Why can't I assign a function to a variable using prototype?

  5. 5

    Why my variable is undefined inside the function

  6. 6

    Why is global variable readable, but not writeable inside a function?

  7. 7

    prototype method is not a function,why?

  8. 8

    Why is it possible to store more than one characters in a "char" variable?

  9. 9

    Is it better to store array in a variable or directly pass an array to a function inside a loop?

  10. 10

    Is it better to store array in a variable or directly pass an array to a function inside a loop?

  11. 11

    require function inside or outside of prototype?

  12. 12

    'this' inside each function in Prototype JS

  13. 13

    require function inside or outside of prototype?

  14. 14

    Calling a function listed inside a prototype

  15. 15

    Accessing "this" in Function.prototype not possible?

  16. 16

    Why is the function argument not overwritten on creating variable of same name inside the function?

  17. 17

    Why am I unable to declare a variable inside a function with a nested function?

  18. 18

    Store function inside an array

  19. 19

    Store function inside an array

  20. 20

    Why is it not possible to access other variables from inside the apply function in Python?

  21. 21

    Why isn't .forEach() working inside Array.prototype.fillB()? (a custom function)

  22. 22

    Why does JavaScript let you store an array and a function in one variable?

  23. 23

    Why store the result of getElementById() to a variable instead of using the function everytime?

  24. 24

    Why use "[*]" instead of "[]" in function prototype?

  25. 25

    Javascript: Why array variable assignment is behaving differently inside and outside this function?

  26. 26

    Why doesn't use the variable value inside the function in python

  27. 27

    Python - Store function in variable

  28. 28

    Store function result into variable

  29. 29

    Store function result into variable

HotTag

Archive