Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. boopathi revised this gist Jun 25, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript_prototype_objects.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ ObjectConstructor.prototype.sayHello = function() {
    alert(this.message);
    };

    /*

    //In this way, you can set multiple functions
    //Avoids writing ObjectConstructor.prototype everytime while defining a function
    ObjectContructor.prototype = {
  2. boopathi revised this gist Jun 25, 2011. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions javascript_prototype_objects.js
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,24 @@ ObjectConstructor.prototype.sayHello = function() {
    alert(this.message);
    };

    /*
    //In this way, you can set multiple functions
    //Avoids writing ObjectConstructor.prototype everytime while defining a function
    ObjectContructor.prototype = {
    sayHello: function() {
    alert(this.message);
    },
    setMessage: function(message) {
    this.message = message;
    }
    };

    // Using your Prototype object

    var object = new ObjectConstructor();
    object.sayHello();

    var object = new ObjectConstructor('Hello Mexpolk!');
    object.sayHello();
    object.setMessage("Hello Boopathi");
    object.sayHello();
  3. @IvanTorresEdge IvanTorresEdge renamed this gist Jan 19, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @IvanTorresEdge IvanTorresEdge created this gist Jan 19, 2010.
    18 changes: 18 additions & 0 deletions prototype.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // Defining constructor function
    function ObjectConstructor(message) {
    // TODO: Add your own initialization code here
    this.message = message || 'Hello Prototype World!';
    };

    // Defining an instance function
    ObjectConstructor.prototype.sayHello = function() {
    alert(this.message);
    };

    // Using your Prototype object

    var object = new ObjectConstructor();
    object.sayHello();

    var object = new ObjectConstructor('Hello Mexpolk!');
    object.sayHello();