Created
October 18, 2017 18:29
-
-
Save GNSubrahmanyam/c1d980f5626b34cee7000820b5e0d1c6 to your computer and use it in GitHub Desktop.
JavaScript Custom Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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