-1

I am working on a project whereby i have noticed there are multiple references to the same objects in different areas. But i have been reading on mixins and just prototypal inheritance but not sure which one to follow:

So my current objects look like below but i need for product to inherit the base class including the function which is used everytime.

var base = function() {
    this.id = 0;
    this.refererer = null;
    this.getCurrency = function() {
        return "US"
    }
}

var product = function() {
    this.name = "";
    this.description = "";
}

How can i implement the above to use either mixins or prototypal inheritance?

wpp
  • 7,093
  • 4
  • 33
  • 65
tjhack
  • 1,022
  • 3
  • 20
  • 43
  • possible duplicate of [How to inherit from a class in javascript?](http://stackoverflow.com/questions/2107556/how-to-inherit-from-a-class-in-javascript) – kemicofa ghost May 12 '15 at 07:58

1 Answers1

0
var base = function() {
        this.id = 0;
        this.refererer = null;
        this.getCurrency = function() {
            return "US"
        }
    }

var product = function() {
        this.name = "";
        this.description = "";
    } 
product.prototype = new base(); // this will do the inheritance trick
product.prototype.constructor = product;

var proObj = new product();
alert(proObj.id);   // 0 base class property "id"
ozil
  • 6,930
  • 9
  • 33
  • 56