difference between function pointers in C and java script functions? Like in C we can pass functions as parameters and execute that function with in other function. In java script also we can pass function basically objects as parameters. Are both the concepts same?
Asked
Active
Viewed 61 times
0
-
1Yes, they work the same. – Derek Pollard Nov 24 '16 at 03:06
-
3Passing functions and calling them is essentially the same. The big difference is that Javascript functions are closures, C function pointers are not. If you don't understand that, see http://stackoverflow.com/questions/111102/how-do-javascript-closures-work?rq=1 – Barmar Nov 24 '16 at 03:15
-
@Derek No they're not. There are similarities, but javascript function objects are much more powerful than C function pointers. – Gene Nov 24 '16 at 03:30
-
@gene no they're not what? They both work the exact way as OP described. – Derek Pollard Nov 24 '16 at 03:33
-
@Derek Folow Barmar's advice and read about closures. Javascript functions bind the environment of the scope where they're defined. C functions don't. E.g. in javascript you can say `var make_incrementer = function(by) { return function (x) { return x + by } }; f = make_incrementer(3); alert(f(7))` This will print 10. C function pointers don't allow that. – Gene Nov 24 '16 at 03:44
-
@gene that wasn't the question though – Derek Pollard Nov 24 '16 at 04:10