KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Let's say I have these two functions: function fnChanger(fn) { fn = function() { sys.print('Changed!'); } } function foo() { sys.print('Unchanged'); } Now, if I call foo() , I see Unchanged , as expected. However, if I call fnChanger first, I still see Unchanged : fnChanger(foo); foo(); //Unchanged Now, I assume this is because foo is not being passed to fnChanger by reference, but I may be wrong. Why does fnChanger not change foo to print Changed! ? Furthermore, how can I get fnChanger to change foo without too much messy syntax? PS: I'm using node.js to test all this stuff, so that's where the sys.print comes from.
Tags (comma-separated)
Save Edits
Cancel