chullman
5/21/2018 - 3:54 AM

inheritence

INHERITENCE:

var shoe = { size: 6, gender: "women", construction: "slipper" };

var magicShoe = Object.create(shoe);


CONSTRUCTOR:

function Shoe (shoeSize, shoeColor, forGender, constructStyle) {
  this.size = shoeSize;
  this.color = shoeColor;
  this.gender= forGender;
  this.construction = constructStyle;
  
}

(note: constructors can be function expressions too)

Shoe.prototype = {
  putOn: function () { alert("Shoe's on!"); }
};

var beachShoe = new Shoe(10, "blue", "women", "flipflop");


RETURNING BACK A PROTOTYPE OBJECT:

var twister = new Tornado("F5", cities, 220);

twister.__proto__;

or

twister.constructor.prototype;


CREATING MULTIPLE PROTOYPE FUNCTIONS:

Fencepost.prototype = {
  sendRopeTo: function(connectedPost) {
    this.connectionsTo.push(connectedPost);
  },
  removeRope: function(removeTo) {
    var temp = [];
    for (var i = 0; i < this.connectionsTo.length; i++) {
      if (this.connectionsTo[i].postNum != removeTo) {
        temp.push(this.connectionsTo[i]);
      }
    }
    this.connectionsTo = temp;
  },
  movePost: function(x, y) {
    this.x = x;
    this.y = y;
  },
  valueOf: function() {
  return Math.sqrt(this.x * this.x +
                   this.y * this.y);
  }
};