+ 2

Can you write a function plz like this function a(x){} that you don't use of "this"??

24th Apr 2018, 5:08 PM
Sina
Sina - avatar
5 Answers
+ 2
It's a function that you provide to tell another function to do something. example: when you see a mouse click. do click function. when the keyboard d key is pressed. do the move character right function but you have to provide function so JavaScript knows what to do. Callbacks are used in asynchronous programs, ie when you want something to happen in the future, ie call me back when you have something for me. In your navigator example, it will execute your callback function every time there is a change to your location.
24th Apr 2018, 7:17 PM
Mike Choy
Mike Choy - avatar
+ 1
Hi Sina in JavaScript you don't need "this" unless you want to have a constructor. If you are writing a standalone function just use normal function declaration or function expression. eg. function double (x) { return x+x} // function declaration by the way all functions have a implicit "this" property, but that is for another day.
24th Apr 2018, 6:45 PM
Mike Choy
Mike Choy - avatar
+ 1
You say true but I saw some function's like this navigator.geoLocation.getCurrentposition(function(position){ }) see the position in this function what is that??
24th Apr 2018, 7:01 PM
Sina
Sina - avatar
+ 1
Hi Sina that is known as a call back function. you pass a function as a parameter. The navigator.geoLocation.getCurrentposition function will execute the callback function you provide when it gets a lock on your position.
24th Apr 2018, 7:10 PM
Mike Choy
Mike Choy - avatar
+ 1
What is call back?
24th Apr 2018, 7:11 PM
Sina
Sina - avatar