Converting Functions to Arrow functions [duplicate]What does “this” refer to in arrow functions in ES6?Is there an “exists” function for jQuery?What's the difference between a method and a function?How can I convert a string to boolean in JavaScript?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionConvert a string to an integer in JavaScript?Convert form data to JavaScript object with jQueryWhat does the exclamation mark do before the function?ECMAScript 6 arrow function that returns an objectAre ES6 arrow functions incompatible with Angular?

Did arcade monitors have same pixel aspect ratio as TV sets?

It grows, but water kills it

Moving brute-force search to FPGA

PTIJ: Haman's bad computer

What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?

Mimic lecturing on blackboard, facing audience

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Why "had" in "[something] we would have made had we used [something]"?

What if a revenant (monster) gains fire resistance?

Do the primes contain an infinite almost arithmetic progression?

How can I write humor as character trait?

Is there a RAID 0 Equivalent for RAM?

How to explain what's wrong with this application of the chain rule?

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Does IPv6 have similar concept of network mask?

Why should universal income be universal?

Biological Blimps: Propulsion

Why is the "ls" command showing permissions of files in a FAT32 partition?

Creepy dinosaur pc game identification

Has any country ever had 2 former presidents in jail simultaneously?

Limits and Infinite Integration by Parts

On a tidally locked planet, would time be quantized?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Pre-mixing cryogenic fuels and using only one fuel tank



Converting Functions to Arrow functions [duplicate]


What does “this” refer to in arrow functions in ES6?Is there an “exists” function for jQuery?What's the difference between a method and a function?How can I convert a string to boolean in JavaScript?var functionName = function() vs function functionName() Set a default parameter value for a JavaScript functionConvert a string to an integer in JavaScript?Convert form data to JavaScript object with jQueryWhat does the exclamation mark do before the function?ECMAScript 6 arrow function that returns an objectAre ES6 arrow functions incompatible with Angular?













6
















This question already has an answer here:



  • What does “this” refer to in arrow functions in ES6?

    5 answers



I'm learning ES6, I just want to convert my ES5 knowledge to ES6.



here's my ES5 code:



function click() 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
;


and here's my ES6 code:



const click = () => 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
console.log('RENDERING');



My problem is this.className += ' grab'; and setTimeout(() => (this.className = 'remove'), 0); didn't run the function. But console.log shows on the log.




Is this method don't work on arrow functions?











share|improve this question













marked as duplicate by adiga, Community Mar 15 at 8:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

    – Jaromanda X
    Mar 15 at 4:12







  • 2





    this keyword functions differently in arrow functions. Read this section of the documentation.

    – Yong Quan
    Mar 15 at 4:19






  • 3





    Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

    – James
    Mar 15 at 4:27






  • 1





    This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

    – Jaromanda X
    Mar 15 at 4:31















6
















This question already has an answer here:



  • What does “this” refer to in arrow functions in ES6?

    5 answers



I'm learning ES6, I just want to convert my ES5 knowledge to ES6.



here's my ES5 code:



function click() 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
;


and here's my ES6 code:



const click = () => 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
console.log('RENDERING');



My problem is this.className += ' grab'; and setTimeout(() => (this.className = 'remove'), 0); didn't run the function. But console.log shows on the log.




Is this method don't work on arrow functions?











share|improve this question













marked as duplicate by adiga, Community Mar 15 at 8:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

    – Jaromanda X
    Mar 15 at 4:12







  • 2





    this keyword functions differently in arrow functions. Read this section of the documentation.

    – Yong Quan
    Mar 15 at 4:19






  • 3





    Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

    – James
    Mar 15 at 4:27






  • 1





    This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

    – Jaromanda X
    Mar 15 at 4:31













6












6








6









This question already has an answer here:



  • What does “this” refer to in arrow functions in ES6?

    5 answers



I'm learning ES6, I just want to convert my ES5 knowledge to ES6.



here's my ES5 code:



function click() 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
;


and here's my ES6 code:



const click = () => 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
console.log('RENDERING');



My problem is this.className += ' grab'; and setTimeout(() => (this.className = 'remove'), 0); didn't run the function. But console.log shows on the log.




Is this method don't work on arrow functions?











share|improve this question















This question already has an answer here:



  • What does “this” refer to in arrow functions in ES6?

    5 answers



I'm learning ES6, I just want to convert my ES5 knowledge to ES6.



here's my ES5 code:



function click() 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
;


and here's my ES6 code:



const click = () => 
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
console.log('RENDERING');



My problem is this.className += ' grab'; and setTimeout(() => (this.className = 'remove'), 0); didn't run the function. But console.log shows on the log.




Is this method don't work on arrow functions?






This question already has an answer here:



  • What does “this” refer to in arrow functions in ES6?

    5 answers







javascript function arrow-functions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 15 at 4:10









code for moneycode for money

363




363




marked as duplicate by adiga, Community Mar 15 at 8:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by adiga, Community Mar 15 at 8:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

    – Jaromanda X
    Mar 15 at 4:12







  • 2





    this keyword functions differently in arrow functions. Read this section of the documentation.

    – Yong Quan
    Mar 15 at 4:19






  • 3





    Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

    – James
    Mar 15 at 4:27






  • 1





    This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

    – Jaromanda X
    Mar 15 at 4:31












  • 1





    this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

    – Jaromanda X
    Mar 15 at 4:12







  • 2





    this keyword functions differently in arrow functions. Read this section of the documentation.

    – Yong Quan
    Mar 15 at 4:19






  • 3





    Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

    – James
    Mar 15 at 4:27






  • 1





    This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

    – Jaromanda X
    Mar 15 at 4:31







1




1





this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

– Jaromanda X
Mar 15 at 4:12






this is not a method, and is different inside an arrow function - read documentation to understand the difference ... didn't run the function yes, it did, you just don't know what you're doing yet

– Jaromanda X
Mar 15 at 4:12





2




2





this keyword functions differently in arrow functions. Read this section of the documentation.

– Yong Quan
Mar 15 at 4:19





this keyword functions differently in arrow functions. Read this section of the documentation.

– Yong Quan
Mar 15 at 4:19




3




3





Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

– James
Mar 15 at 4:27





Aside - Consider using el.classList.add('grab') (and el.classList.remove('grab')) instead of manipulating the string of class names manually. more info

– James
Mar 15 at 4:27




1




1





This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

– Jaromanda X
Mar 15 at 4:31





This shows that not all functions should be converted to arrow functions just because arrow functions are cool :p arrow functions serve a specific purpose and should only be used as appropriate

– Jaromanda X
Mar 15 at 4:31












6 Answers
6






active

oldest

votes


















7














There's not really enough context to give you a good answer, but one thing stands out. Arrow functions maintain scope, so this inside function click() and const click may well be different. In the ES6 version, this will refer to whatever was this during the closure creation, which may not be what you want.



Arrow Functions at MDN clears it up:




An arrow function does not have its own this.




…Which means that this will be inherited from the declaring scope.



ES6 arrow functions aren't just a new way of declaring functions, and there's nothing inherently wrong with function myFunction(...) syntax, nor is it going away. Arrow functions avoid some verbosity when passing a function as an argument (e.g. to forEach) and avoid the need to rebind a function to a different this in some cases. Converting all function declarations to arrow syntax is not an upgrade.






share|improve this answer

























  • @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

    – adc
    Mar 15 at 4:29


















0














The reason is that you just need to slightly restructure things.



setTimeout(() => this.className = 'remove', 0)


You have parenthesis vs curly braces.



your this may or may not work depending on how things are structured in the other code






share|improve this answer

























  • absolutely no difference in this context - in other context, the difference is what the arrow function returns

    – Jaromanda X
    Mar 15 at 4:27


















0














In Arrow Functions, this isn't the this you would expect. this in Arrow Functions is defined when you create the function - not when it is called. See here for more information on that.



Thanks to @Jaromanda X from the comments - In this case, keep using standard function notation (function() ...) - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails






share|improve this answer




















  • 1





    this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

    – Jaromanda X
    Mar 15 at 4:26











  • @JaromandaX you're right. let me fix that

    – Aniket G
    Mar 15 at 4:27











  • keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

    – Jaromanda X
    Mar 15 at 4:32












  • @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

    – Aniket G
    Mar 15 at 4:34











  • Feel free - it's one of my better ones :p

    – Jaromanda X
    Mar 15 at 4:35


















0














 const click = () => 
console.log(this);
this.className += ' grab';
setTimeout(() => (this.className = 'remove'), 0);
console.log('RENDERING');

click();


'this' in the arrow function represents from wherever it is called. for eg if i open the browser and goto console and type above code then 'this' will become window object since the function is called from global enviroment. Also arrow function doesnot have its own 'this'.






share|improve this answer






























    0














    You can bind this for arrow function to access functions and data. Your code should be something like



    const click = () => 
    this.className += ' grab';
    setTimeout(() => (this.className = 'remove'), 0);
    console.log('RENDERING');
    .bind(this)


    It will bind this for arrow function and you can access those variable and functions.






    share|improve this answer























    • it will bind this only if it's defined in the object though

      – somebody
      Mar 15 at 6:15



















    0














    An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.






    share|improve this answer





























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      There's not really enough context to give you a good answer, but one thing stands out. Arrow functions maintain scope, so this inside function click() and const click may well be different. In the ES6 version, this will refer to whatever was this during the closure creation, which may not be what you want.



      Arrow Functions at MDN clears it up:




      An arrow function does not have its own this.




      …Which means that this will be inherited from the declaring scope.



      ES6 arrow functions aren't just a new way of declaring functions, and there's nothing inherently wrong with function myFunction(...) syntax, nor is it going away. Arrow functions avoid some verbosity when passing a function as an argument (e.g. to forEach) and avoid the need to rebind a function to a different this in some cases. Converting all function declarations to arrow syntax is not an upgrade.






      share|improve this answer

























      • @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

        – adc
        Mar 15 at 4:29















      7














      There's not really enough context to give you a good answer, but one thing stands out. Arrow functions maintain scope, so this inside function click() and const click may well be different. In the ES6 version, this will refer to whatever was this during the closure creation, which may not be what you want.



      Arrow Functions at MDN clears it up:




      An arrow function does not have its own this.




      …Which means that this will be inherited from the declaring scope.



      ES6 arrow functions aren't just a new way of declaring functions, and there's nothing inherently wrong with function myFunction(...) syntax, nor is it going away. Arrow functions avoid some verbosity when passing a function as an argument (e.g. to forEach) and avoid the need to rebind a function to a different this in some cases. Converting all function declarations to arrow syntax is not an upgrade.






      share|improve this answer

























      • @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

        – adc
        Mar 15 at 4:29













      7












      7








      7







      There's not really enough context to give you a good answer, but one thing stands out. Arrow functions maintain scope, so this inside function click() and const click may well be different. In the ES6 version, this will refer to whatever was this during the closure creation, which may not be what you want.



      Arrow Functions at MDN clears it up:




      An arrow function does not have its own this.




      …Which means that this will be inherited from the declaring scope.



      ES6 arrow functions aren't just a new way of declaring functions, and there's nothing inherently wrong with function myFunction(...) syntax, nor is it going away. Arrow functions avoid some verbosity when passing a function as an argument (e.g. to forEach) and avoid the need to rebind a function to a different this in some cases. Converting all function declarations to arrow syntax is not an upgrade.






      share|improve this answer















      There's not really enough context to give you a good answer, but one thing stands out. Arrow functions maintain scope, so this inside function click() and const click may well be different. In the ES6 version, this will refer to whatever was this during the closure creation, which may not be what you want.



      Arrow Functions at MDN clears it up:




      An arrow function does not have its own this.




      …Which means that this will be inherited from the declaring scope.



      ES6 arrow functions aren't just a new way of declaring functions, and there's nothing inherently wrong with function myFunction(...) syntax, nor is it going away. Arrow functions avoid some verbosity when passing a function as an argument (e.g. to forEach) and avoid the need to rebind a function to a different this in some cases. Converting all function declarations to arrow syntax is not an upgrade.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 15 at 4:25

























      answered Mar 15 at 4:19









      adcadc

      32127




      32127












      • @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

        – adc
        Mar 15 at 4:29

















      • @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

        – adc
        Mar 15 at 4:29
















      @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

      – adc
      Mar 15 at 4:29





      @jaromanda-x Yeah, you're probably right, especially if you assume that the function is normally called as an object method, which is why it would even have a className property. Shrug.

      – adc
      Mar 15 at 4:29













      0














      The reason is that you just need to slightly restructure things.



      setTimeout(() => this.className = 'remove', 0)


      You have parenthesis vs curly braces.



      your this may or may not work depending on how things are structured in the other code






      share|improve this answer

























      • absolutely no difference in this context - in other context, the difference is what the arrow function returns

        – Jaromanda X
        Mar 15 at 4:27















      0














      The reason is that you just need to slightly restructure things.



      setTimeout(() => this.className = 'remove', 0)


      You have parenthesis vs curly braces.



      your this may or may not work depending on how things are structured in the other code






      share|improve this answer

























      • absolutely no difference in this context - in other context, the difference is what the arrow function returns

        – Jaromanda X
        Mar 15 at 4:27













      0












      0








      0







      The reason is that you just need to slightly restructure things.



      setTimeout(() => this.className = 'remove', 0)


      You have parenthesis vs curly braces.



      your this may or may not work depending on how things are structured in the other code






      share|improve this answer















      The reason is that you just need to slightly restructure things.



      setTimeout(() => this.className = 'remove', 0)


      You have parenthesis vs curly braces.



      your this may or may not work depending on how things are structured in the other code







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 15 at 4:26

























      answered Mar 15 at 4:24









      Jon BlackJon Black

      860718




      860718












      • absolutely no difference in this context - in other context, the difference is what the arrow function returns

        – Jaromanda X
        Mar 15 at 4:27

















      • absolutely no difference in this context - in other context, the difference is what the arrow function returns

        – Jaromanda X
        Mar 15 at 4:27
















      absolutely no difference in this context - in other context, the difference is what the arrow function returns

      – Jaromanda X
      Mar 15 at 4:27





      absolutely no difference in this context - in other context, the difference is what the arrow function returns

      – Jaromanda X
      Mar 15 at 4:27











      0














      In Arrow Functions, this isn't the this you would expect. this in Arrow Functions is defined when you create the function - not when it is called. See here for more information on that.



      Thanks to @Jaromanda X from the comments - In this case, keep using standard function notation (function() ...) - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails






      share|improve this answer




















      • 1





        this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

        – Jaromanda X
        Mar 15 at 4:26











      • @JaromandaX you're right. let me fix that

        – Aniket G
        Mar 15 at 4:27











      • keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

        – Jaromanda X
        Mar 15 at 4:32












      • @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

        – Aniket G
        Mar 15 at 4:34











      • Feel free - it's one of my better ones :p

        – Jaromanda X
        Mar 15 at 4:35















      0














      In Arrow Functions, this isn't the this you would expect. this in Arrow Functions is defined when you create the function - not when it is called. See here for more information on that.



      Thanks to @Jaromanda X from the comments - In this case, keep using standard function notation (function() ...) - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails






      share|improve this answer




















      • 1





        this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

        – Jaromanda X
        Mar 15 at 4:26











      • @JaromandaX you're right. let me fix that

        – Aniket G
        Mar 15 at 4:27











      • keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

        – Jaromanda X
        Mar 15 at 4:32












      • @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

        – Aniket G
        Mar 15 at 4:34











      • Feel free - it's one of my better ones :p

        – Jaromanda X
        Mar 15 at 4:35













      0












      0








      0







      In Arrow Functions, this isn't the this you would expect. this in Arrow Functions is defined when you create the function - not when it is called. See here for more information on that.



      Thanks to @Jaromanda X from the comments - In this case, keep using standard function notation (function() ...) - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails






      share|improve this answer















      In Arrow Functions, this isn't the this you would expect. this in Arrow Functions is defined when you create the function - not when it is called. See here for more information on that.



      Thanks to @Jaromanda X from the comments - In this case, keep using standard function notation (function() ...) - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 15 at 4:36

























      answered Mar 15 at 4:24









      Aniket GAniket G

      2,4211528




      2,4211528







      • 1





        this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

        – Jaromanda X
        Mar 15 at 4:26











      • @JaromandaX you're right. let me fix that

        – Aniket G
        Mar 15 at 4:27











      • keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

        – Jaromanda X
        Mar 15 at 4:32












      • @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

        – Aniket G
        Mar 15 at 4:34











      • Feel free - it's one of my better ones :p

        – Jaromanda X
        Mar 15 at 4:35












      • 1





        this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

        – Jaromanda X
        Mar 15 at 4:26











      • @JaromandaX you're right. let me fix that

        – Aniket G
        Mar 15 at 4:27











      • keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

        – Jaromanda X
        Mar 15 at 4:32












      • @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

        – Aniket G
        Mar 15 at 4:34











      • Feel free - it's one of my better ones :p

        – Jaromanda X
        Mar 15 at 4:35







      1




      1





      this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

      – Jaromanda X
      Mar 15 at 4:26





      this does exist, otherwise the OP would get errors - this is from the bounding lexical scope

      – Jaromanda X
      Mar 15 at 4:26













      @JaromandaX you're right. let me fix that

      – Aniket G
      Mar 15 at 4:27





      @JaromandaX you're right. let me fix that

      – Aniket G
      Mar 15 at 4:27













      keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

      – Jaromanda X
      Mar 15 at 4:32






      keep using standard function notation - i.e. just because you bought a new screwdriver, doesn't mean the old hammer isn't still the best tool for banging in nails

      – Jaromanda X
      Mar 15 at 4:32














      @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

      – Aniket G
      Mar 15 at 4:34





      @JaromandaX that's actually a very good analogy. Do you mind if I put that in my answer?

      – Aniket G
      Mar 15 at 4:34













      Feel free - it's one of my better ones :p

      – Jaromanda X
      Mar 15 at 4:35





      Feel free - it's one of my better ones :p

      – Jaromanda X
      Mar 15 at 4:35











      0














       const click = () => 
      console.log(this);
      this.className += ' grab';
      setTimeout(() => (this.className = 'remove'), 0);
      console.log('RENDERING');

      click();


      'this' in the arrow function represents from wherever it is called. for eg if i open the browser and goto console and type above code then 'this' will become window object since the function is called from global enviroment. Also arrow function doesnot have its own 'this'.






      share|improve this answer



























        0














         const click = () => 
        console.log(this);
        this.className += ' grab';
        setTimeout(() => (this.className = 'remove'), 0);
        console.log('RENDERING');

        click();


        'this' in the arrow function represents from wherever it is called. for eg if i open the browser and goto console and type above code then 'this' will become window object since the function is called from global enviroment. Also arrow function doesnot have its own 'this'.






        share|improve this answer

























          0












          0








          0







           const click = () => 
          console.log(this);
          this.className += ' grab';
          setTimeout(() => (this.className = 'remove'), 0);
          console.log('RENDERING');

          click();


          'this' in the arrow function represents from wherever it is called. for eg if i open the browser and goto console and type above code then 'this' will become window object since the function is called from global enviroment. Also arrow function doesnot have its own 'this'.






          share|improve this answer













           const click = () => 
          console.log(this);
          this.className += ' grab';
          setTimeout(() => (this.className = 'remove'), 0);
          console.log('RENDERING');

          click();


          'this' in the arrow function represents from wherever it is called. for eg if i open the browser and goto console and type above code then 'this' will become window object since the function is called from global enviroment. Also arrow function doesnot have its own 'this'.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 15 at 4:37









          Kaushal RegmiKaushal Regmi

          538




          538





















              0














              You can bind this for arrow function to access functions and data. Your code should be something like



              const click = () => 
              this.className += ' grab';
              setTimeout(() => (this.className = 'remove'), 0);
              console.log('RENDERING');
              .bind(this)


              It will bind this for arrow function and you can access those variable and functions.






              share|improve this answer























              • it will bind this only if it's defined in the object though

                – somebody
                Mar 15 at 6:15
















              0














              You can bind this for arrow function to access functions and data. Your code should be something like



              const click = () => 
              this.className += ' grab';
              setTimeout(() => (this.className = 'remove'), 0);
              console.log('RENDERING');
              .bind(this)


              It will bind this for arrow function and you can access those variable and functions.






              share|improve this answer























              • it will bind this only if it's defined in the object though

                – somebody
                Mar 15 at 6:15














              0












              0








              0







              You can bind this for arrow function to access functions and data. Your code should be something like



              const click = () => 
              this.className += ' grab';
              setTimeout(() => (this.className = 'remove'), 0);
              console.log('RENDERING');
              .bind(this)


              It will bind this for arrow function and you can access those variable and functions.






              share|improve this answer













              You can bind this for arrow function to access functions and data. Your code should be something like



              const click = () => 
              this.className += ' grab';
              setTimeout(() => (this.className = 'remove'), 0);
              console.log('RENDERING');
              .bind(this)


              It will bind this for arrow function and you can access those variable and functions.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 15 at 4:40









              ZearaeZZearaeZ

              710518




              710518












              • it will bind this only if it's defined in the object though

                – somebody
                Mar 15 at 6:15


















              • it will bind this only if it's defined in the object though

                – somebody
                Mar 15 at 6:15

















              it will bind this only if it's defined in the object though

              – somebody
              Mar 15 at 6:15






              it will bind this only if it's defined in the object though

              – somebody
              Mar 15 at 6:15












              0














              An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.






              share|improve this answer



























                0














                An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.






                share|improve this answer

























                  0












                  0








                  0







                  An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.






                  share|improve this answer













                  An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 15 at 5:03









                  Bathri NathanBathri Nathan

                  24918




                  24918













                      Popular posts from this blog

                      Solar Wings Breeze Design and development Specifications (Breeze) References Navigation menu1368-485X"Hang glider: Breeze (Solar Wings)"e

                      Kathakali Contents Etymology and nomenclature History Repertoire Songs and musical instruments Traditional plays Styles: Sampradayam Training centers and awards Relationship to other dance forms See also Notes References External links Navigation menueThe Illustrated Encyclopedia of Hinduism: A-MSouth Asian Folklore: An EncyclopediaRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to Play10.1353/atj.2005.0004The Illustrated Encyclopedia of Hinduism: A-MEncyclopedia of HinduismKathakali Dance-drama: Where Gods and Demons Come to PlaySonic Liturgy: Ritual and Music in Hindu Tradition"The Mirror of Gesture"Kathakali Dance-drama: Where Gods and Demons Come to Play"Kathakali"Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceMedieval Indian Literature: An AnthologyThe Oxford Companion to Indian TheatreSouth Asian Folklore: An Encyclopedia : Afghanistan, Bangladesh, India, Nepal, Pakistan, Sri LankaThe Rise of Performance Studies: Rethinking Richard Schechner's Broad SpectrumIndian Theatre: Traditions of PerformanceModern Asian Theatre and Performance 1900-2000Critical Theory and PerformanceBetween Theater and AnthropologyKathakali603847011Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceBetween Theater and AnthropologyBetween Theater and AnthropologyNambeesan Smaraka AwardsArchivedThe Cambridge Guide to TheatreRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeThe Garland Encyclopedia of World Music: South Asia : the Indian subcontinentThe Ethos of Noh: Actors and Their Art10.2307/1145740By Means of Performance: Intercultural Studies of Theatre and Ritual10.1017/s204912550000100xReconceiving the Renaissance: A Critical ReaderPerformance TheoryListening to Theatre: The Aural Dimension of Beijing Opera10.2307/1146013Kathakali: The Art of the Non-WorldlyOn KathakaliKathakali, the dance theatreThe Kathakali Complex: Performance & StructureKathakali Dance-Drama: Where Gods and Demons Come to Play10.1093/obo/9780195399318-0071Drama and Ritual of Early Hinduism"In the Shadow of Hollywood Orientalism: Authentic East Indian Dancing"10.1080/08949460490274013Sanskrit Play Production in Ancient IndiaIndian Music: History and StructureBharata, the Nāṭyaśāstra233639306Table of Contents2238067286469807Dance In Indian Painting10.2307/32047833204783Kathakali Dance-Theatre: A Visual Narrative of Sacred Indian MimeIndian Classical Dance: The Renaissance and BeyondKathakali: an indigenous art-form of Keralaeee

                      Method to test if a number is a perfect power? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Detecting perfect squares faster than by extracting square rooteffective way to get the integer sequence A181392 from oeisA rarely mentioned fact about perfect powersHow many numbers such $n$ are there that $n<100,lfloorsqrtn rfloor mid n$Check perfect squareness by modulo division against multiple basesFor what pair of integers $(a,b)$ is $3^a + 7^b$ a perfect square.Do there exist any positive integers $n$ such that $lfloore^nrfloor$ is a perfect power? What is the probability that one exists?finding perfect power factors of an integerProve that the sequence contains a perfect square for any natural number $m $ in the domain of $f$ .Counting Perfect Powers