Javascript: pass function by reference, rather than by value

Bluefire

If I have

var foo = function() {
    console.log('foo');
}, bar = foo;

and call bar(), the console logs foo. If then, I do

foo = function() {
    console.log('not foo');
}

and call bar(), the console still logs foo. How can I get around this?

just somebody

what you're trying to do is not very wise, but i'll hand you the shotgun, blast off! (your legs i mean.)

var foo = function () { console.log("foo"); }
var bar = function () { foo(); }
bar();
var foo = function () { console.log("qux"); }
bar();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript: pass function by reference, rather than by value

From Dev

Passing iterator value rather than reference to function

From Dev

(() => {}) rather than the JavaScript function expression

From Dev

Why use a function rather than a reference to member?

From Dev

JavaScript: is it possible for closures to access variables in the enclosing scope by value rather than by reference like in PHP?

From Dev

Is there a way to pass a copy of the object rather than reference to Java method

From Dev

Is there a way to pass a copy of the object rather than reference to Java method

From Dev

Javascript pass by reference or value?

From Dev

Pass by Value and Pass by Reference in Javascript

From Dev

Pass by value faster than pass by reference

From Dev

How to store data in Django cache as a reference rather than value.?

From Dev

How to pass an array to a function as an actual parameter rather than a global variable

From Dev

Protractor/Javascript - Reference syntax to pass function into a value for expect clause

From Dev

Pass by reference and value in javascript / jquery

From Dev

Function returns nothing rather than the expected value "None"

From Dev

Function returns nothing rather than the expected value "None"

From Dev

Unexpected JavaScript (jQuery) Behavior (Function call, rather than Form submit)

From Dev

simple way rather than to call a function repeatedly in javascript

From Dev

Would it be a good idea to pass an Error object by reference rather than throwing exceptions from a method?

From Dev

Is pass by reference (a vector of pointers to object) faster than pass by value?

From Dev

Is pass by reference (a vector of pointers to object) faster than pass by value?

From Dev

Javascript Pass a function, store its reference, change its value to another function

From Dev

C++ pass by value / by reference function overload

From Dev

C string function calls, pass by value or reference?

From Dev

Why allocation functions take std::nothrow_t by reference rather than by value?

From Dev

How do I ensure an array operation is done by value rather than reference in ruby?

From Dev

Collection of Collections - How to make sub-collections by value rather than reference?

From Dev

Reference directive attribute with vm rather than $scope

From Dev

Returning reference to trait rather than struct

Related Related

  1. 1

    Javascript: pass function by reference, rather than by value

  2. 2

    Passing iterator value rather than reference to function

  3. 3

    (() => {}) rather than the JavaScript function expression

  4. 4

    Why use a function rather than a reference to member?

  5. 5

    JavaScript: is it possible for closures to access variables in the enclosing scope by value rather than by reference like in PHP?

  6. 6

    Is there a way to pass a copy of the object rather than reference to Java method

  7. 7

    Is there a way to pass a copy of the object rather than reference to Java method

  8. 8

    Javascript pass by reference or value?

  9. 9

    Pass by Value and Pass by Reference in Javascript

  10. 10

    Pass by value faster than pass by reference

  11. 11

    How to store data in Django cache as a reference rather than value.?

  12. 12

    How to pass an array to a function as an actual parameter rather than a global variable

  13. 13

    Protractor/Javascript - Reference syntax to pass function into a value for expect clause

  14. 14

    Pass by reference and value in javascript / jquery

  15. 15

    Function returns nothing rather than the expected value "None"

  16. 16

    Function returns nothing rather than the expected value "None"

  17. 17

    Unexpected JavaScript (jQuery) Behavior (Function call, rather than Form submit)

  18. 18

    simple way rather than to call a function repeatedly in javascript

  19. 19

    Would it be a good idea to pass an Error object by reference rather than throwing exceptions from a method?

  20. 20

    Is pass by reference (a vector of pointers to object) faster than pass by value?

  21. 21

    Is pass by reference (a vector of pointers to object) faster than pass by value?

  22. 22

    Javascript Pass a function, store its reference, change its value to another function

  23. 23

    C++ pass by value / by reference function overload

  24. 24

    C string function calls, pass by value or reference?

  25. 25

    Why allocation functions take std::nothrow_t by reference rather than by value?

  26. 26

    How do I ensure an array operation is done by value rather than reference in ruby?

  27. 27

    Collection of Collections - How to make sub-collections by value rather than reference?

  28. 28

    Reference directive attribute with vm rather than $scope

  29. 29

    Returning reference to trait rather than struct

HotTag

Archive