Skip to content

Chapter 6 Sets code does not work #32

Closed
@saidbakr

Description

@saidbakr

I have the following code that I have get till page 94 of the first edition:

function Set() {
    var items = {};
    
    this.has = function(value) {
        return items.hasOwnProperty(value);
    }
    this.add = function(value){
        if(!this.has(value)){
            items[value] = value;
            return true;
        }
        return false;
    }    
}

var set = new Set();
set.add(1);
set.add(5);
set.add(10);
console.log(set.items); //undefined

The console.log outputs undefined. I'm using Google Chrome Version 62.0.3202.75 64 bit on Ubuntu linux and my files structure is two files:

  1. index.html
  2. js.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions