Created
February 18, 2021 19:58
-
-
Save diazvictor/a99437c5338b6e59d1477816d3168428 to your computer and use it in GitHub Desktop.
How To Create An Object With Javascript
This file contains 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
// This is a practice of the <https://www.sololearn.com/learning/1024/> course. | |
var currentDate = new Date(); | |
function person (name, age) { | |
this.name = name; | |
this.age = age; | |
this.yearOfBirth = currentDate.getFullYear() - this.age; | |
this.seeInfo = function () { | |
console.log( | |
"My name is " + this.name + " and I am " + this.age + " aged. " + | |
"I was born in the year " + this.yearOfBirth | |
); | |
}; | |
} | |
var John = new person("John", 25); | |
var James = new person("James", 21); | |
James.seeInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment