← 输入框|github.com|刷新
Skip to content

Chapter 13 Robot game solution (p. 583 in pdf book) #20

Open

Description

@tygamchenry

Hello,

Why is a function needed under the unlock function? The following doesn't work... why doesn't it?

Game.prototype.unlock = function() {
if (this.level === 42) {
console.log(this.name + " is blasting you with laser beams.");
}
}

...

robby.unlock();
rosie.unlock();

Activity

  1. bethrobson commented on Jul 20, 2017

    @bethrobson
    Owner

    because we don't want lasers only at level 42; we want lasers for all robots that reach level 42 so they keep them after that too. By adding the function to the prototype, you can call deployLaser after you've reached level 42 and gone beyond.

  2. tygamchenry commented on Jul 20, 2017

    @tygamchenry
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions