Difference between functions using public _someName = () => {} and public _someName() {} [duplicate] - javascript

This question already has answers here:
Arrow vs classic method in ES6 class
(1 answer)
What is the difference between class method vs. class field function vs. class field arrow function?
(2 answers)
Javascript class methods versus properties
(2 answers)
ES6 functions, arrow functions and 'this' in an ES6 class [duplicate]
(5 answers)
Closed 3 years ago.
I'm learning JavaScript/ReactJS and I'm finding I'm using functions with these variations:
public _someName = () => {} why the = before round brackets and why the lambda?
and
public _someName() {} What does this one NOT do compared to the above.
I've looked on SO and generally for some clear explanation of the difference but nothing has been found. Can someone tell me what the difference is based on my notes above.
Btw: I've read the docs!

Related

How to dynamically instntiate a class? [duplicate]

This question already has answers here:
Create object from class name in JavasScript ECMAScript 6
(8 answers)
ES6 classes : what about instrospection?
(1 answer)
Javascript ES6 class definition not accessible in window global
(2 answers)
Closed 2 years ago.
I have a class and a function, as follows:
class A {}
function B {}
I need to dynamically instantiate them, in a way similar to Java's class.forName().
I am able to instantiate the function as follows:
new window["B"]
However
window["A"] === undefined
Why the difference? Aren't classes just syntactic sugar for functions?

What is the difference between an object literal and a class in JavaScript? [duplicate]

This question already has answers here:
Should I be using object literals or constructor functions?
(12 answers)
Javascript Object : Literal Vs Constructor [duplicate]
(2 answers)
Object vs Class vs Function
(7 answers)
What is a difference between an object literal and a class with values in constructor in javascript?
(3 answers)
Closed 3 years ago.
I am currently finding it hard to figure out the difference between an object literal and a class.
Here's a link!
This might be helpful for you.
Content of the link:
The most significant difference I can see between creating classes and
literally notated objects is that the latter are entire objects,
whereas classes are not objects, but blueprints from which objects are
created.

how does arrow function with spread operator work [duplicate]

This question already has answers here:
What do multiple arrow functions mean in JavaScript?
(7 answers)
How does the spread syntax in ES6 JS work as a function argument?
(1 answer)
What are these three dots in React doing?
(23 answers)
Closed 5 years ago.
How does this work:
const invert = fn => (...args) => -fn(...args);
Specifically, what is happening with (...args). It behaves as if it is separating the arguments from the function after the first fat arrow, but I suspect there is a better, more specific, explanation. Thanks.

When is the .this keyword unbound in Javascript? [duplicate]

This question already has answers here:
How does the "this" keyword work, and when should it be used?
(22 answers)
Why is JavaScript bind() necessary?
(4 answers)
why do you need to bind a function in a constructor
(6 answers)
Closed 5 years ago.
In what circumstance is the .this keyword unbound? In my react code, I have found that I have to use this.someMethod = this.someMethod.bind(this) in the constructor() to access the properties of that method. Is this only when my method is triggered by an event listener, or is this necessary for all methods? Also are there any other situations that will break the access to .this?

JavaScript Function Declaration vs Object Literal [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Javascript object creation using literals vs custom constructor functions
Function vs. Object Literal Notaion - Which is better, or is it a matter of preference?
Could anyone enlighten me what is the difference between below two ways of creating objects in JavaScript or more specifically drawbacks/advantages of them:
Function Foo() {
function bar () {...}
}
And
var Foo = {
bar : function() {}
}
Also since in latter way, there is no this keyword, how can I make it object instance member ?

Categories