Why is (3) .constructor valid when the "constructor" in (3) is invalid?

(3).constructor- Number, but "constructor" in (3)- TypeError, why?

+3
source share
2 answers

Using the accessor property , the number 3turns into a Number object. And an object of this type has a constructor and therefore a property constructor.

But as ChaosPandion already pointed out , the operator inrequires the correct expression to get the object, but 3it is not an object, but a simple literal.

+3
source

in. , . 5 .

11.8.7

RelationalExpression: RelationalExpression ShiftExpression :

  • lref RelationalExpression.
  • lval - GetValue (lref).
  • rref ShiftExpression.
  • rval - GetValue (rref).
  • (rval) , TypeError.
  • [[HasProperty]] rval ToString (lval).

(3).constructor , , , .

+3

Source: https://habr.com/ru/post/1773034/


All Articles