Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A more interesting implementation of the sit method Question #4

Open
Labels
@SOSANA

Description

@SOSANA

When we call barnaby and spot is the instance object value already set to true automatically even though our prototype is set to false? As I was tracing through trying to understand why the instance object would not be set to false as it inherits from the prototype as it doesn't make sense to me. If it was set to false than the first call would console.log Barnaby is already sitting but if it was true than it would skip this and console.log as show in the example. Scratching my head on this one.

// adding new property for sittingDog.prototype.sitting = false;// adding new method for sitDog.prototype.sit = function() {     if (this.sitting) {        console.log(this.name + " is already sitting");     } else {        this.sitting = true;        console.log(this.name + " is now sitting");     }};barnaby.sit();barnaby.sit();spot.sit();spot.sit();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp