JavaScript - function as an object property

后端 未结 3 1453
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 05:52

Hey everyone, this is #23 from John Resig Advanced JavaScript http://ejohn.org/apps/learn/#23, called

What happens if a function is an object pr

3条回答
  •  忘了有多久
    2021-02-01 06:26

    1) Katana is an object. Katana.use is a function. Its a property that contains a function as value. The value it contains happens to be an anonymous function.

    The distinction is that Katana.use is a property of Katana and that the value of Katana.use is a function. use is a key defined on Katana since Katana["use"] also works.

    2) It's setting isSharp to NOT isSharp so either true -> false or false -> true

    3) the assert is saying katana.isSharp === false which it should be since it was orginally true but then set to false.

提交回复
热议问题