Skip to content

A more interesting implementation of the sit method Question #4

Open
@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 sitting
Dog.prototype.sitting = false;
// adding new method for sit
Dog.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