Skip to content

Instantly share code, notes, and snippets.

@GNSubrahmanyam
Created October 18, 2017 18:29
Show Gist options
  • Select an option

  • Save GNSubrahmanyam/c1d980f5626b34cee7000820b5e0d1c6 to your computer and use it in GitHub Desktop.

Select an option

Save GNSubrahmanyam/c1d980f5626b34cee7000820b5e0d1c6 to your computer and use it in GitHub Desktop.
JavaScript Custom Objects
function Person(obj) {
'use strict';
if (typeof obj === "undefined") {
this.name = "Bob";
this.age = 32;
this.company = "Facebook";
} else {
this.name = obj.name;
this.age = obj.age;
this.company = obj.company;
}
}
Person.prototype.print = function () {
'use strict';
console.log("Name: " + this.name + " Age : " + this.age + " Company : " + this.company);
};
var p1 = new Person({name: "Alex", age: 23, company: "Google"});
p1.print();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment