0

Having trouble accessing a keyvalue pair inside an JS object, getting the following error in chrome:

Uncaught TypeError: undefined is not a function jQuery.event.dispatch jquery-2.1.0.js:4371 jQuery.event.add.elemData.handle

So, here is my code:

//Separate file named Product.js

function Product() {

    var field = {
        ProductName: "False Teeth",
        SupplierID: 7,
    }

    this.init = function () {
        //any initialisation code
    }

    var getProperty = function (propertyName) {
        return field[propertyName];
    }
};


//In another javascript file, trying to access the object

var product = new Product();

//THIS GIVES THE ERROR undefined is not a function
console.log("supplierID:" + product.getProperty("SupplierID")); 

Any ideas?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
user142617
  • 386
  • 2
  • 7
  • 18

1 Answers1

1

Use:

//Separate file named Product.js

function Product() {

    var field = {
        ProductName: "False Teeth",
        SupplierID: 7,
    }

    this.init = function () {
        //any initialisation code
    }

    this.getProperty = function (propertyName) {
        return field[propertyName];
    }
};


//In another javascript file, trying to access the object

var product = new Product();

//THIS GIVES THE ERROR undefined is not a function
console.log("supplierID:" + product.getProperty("SupplierID")); 
Minko Gechev
  • 25,304
  • 9
  • 61
  • 68