Javascript_Travis_02

by Jose Vihano

HTML

<div id="console-log"></div>

JavaScript

(
  function() {
    var consoleLine = "<p class=\"console-line\"></p>";
    console = {
      log: function(text) {
        $("#console-log").append($(consoleLine).html(text));
      }
    };

    var Fruit1 = function(name, color, shape) {
      this.currName = name;
      this.currColor = color;
      this.currShape = shape;
      this.describe = function() {
        return ("The color of " + this.currName + " is " + this.currColor + " and the shape is " + this.currShape);
      };
    };


    var Fruit2 = function(name, color, shape) {
      this.currName = name;
      this.currColor = color;
      this.currShape = shape;
      return {
        describe: function() {
          return ("The color of " + this.currName + " is " + this.currColor + " and the shape is " + this.currShape);
        }.bind(this)
      };
    };

    var apple1 = new Fruit1("Royal Gala", "Red", "Round");
    var apple2 = new Fruit2("Royal Gala", "Red", "Round");
    apple1.currName = "Washington Apple";
    apple2.currName = "Washington Apple";
    console.log(apple1.describe());
    console.log(apple2.describe());
  }
)()