1
class App extends Component {
  constructor() {
    super();
    this.state = {
      counter: 0
    };
  }
  a() {}
  b = () => {}
  render() {
    const c = () => {}
    return ( 
      <Text>Hello World!</Text>
    )
  }
}

Can anybody help me in this. That what is difference between these a,b,c functions and can I access all these from some other class using reference. How can I access it from another class. I searched lot on online but did not received proper answer. \Thanks in advancer

Ivar
  • 6,138
  • 12
  • 49
  • 61
Rover
  • 661
  • 2
  • 18
  • 39
  • `a` is a *method*. A method is like a traditional function (one where `this` is set by how it's called), but it can use `super` if it's in a subclass (as it is in your example). Methods are created once, put on the object that will be used as the prototype of class instances (`App.prototype`), and reused. – T.J. Crowder Jun 08 '21 at 08:39
  • `b` is an *instance property* with an *arrow function* assigned to it. Arrow functions close over `this`, so `this` within a call to `b` will always be the class instance (the component, in your case). A new `b` function is created for each instance, it isn't reused. – T.J. Crowder Jun 08 '21 at 08:39
  • `c` is a *local constant* with an *arrow function* assigned to it which is only accessible within the call to `render` where it's created (unless of course it's passed to something that keeps it after `render` has returned). A new one is created for each call to `render`. – T.J. Crowder Jun 08 '21 at 08:39
  • See the answers the linked questions at the top of your post as well as: 1. [My answer to a closely-related question](https://stackoverflow.com/a/22173438) 2. The [public and private class fields proposal](https://github.com/tc39/proposal-class-fields) which added the instance property definition syntax used for `b` (the property syntax, not arrow functions — those were earlier in ES2015) 3. [*What is the meaning of `=>`*](http://stackoverflow.com/questions/24900875/) 4. [*Arrow function and `this`*](https://stackoverflow.com/questions/43558721/arrow-function-and-this) – T.J. Crowder Jun 08 '21 at 08:40

0 Answers0