P
P
PlasterTom2018-02-01 18:16:03
JavaScript
PlasterTom, 2018-02-01 18:16:03

With or without this?

Why do we do without this in the first example, but not in the second?

function Welcome(props) {
      return <h1>Hello, {props.name}</h1>;
    }

class Welcome extends React.Component {
      render() {
        return <h1>Hello, {this.props.name}</h1>;
      }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-01
@PlasterTom

Because in the first case you are accessing a function argument, and in the second case you are accessing a class field. All according to the canons of JavaScript .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question