Skip to content

Instantly share code, notes, and snippets.

@diazvictor
Created February 18, 2021 19:58
Show Gist options
  • Save diazvictor/a99437c5338b6e59d1477816d3168428 to your computer and use it in GitHub Desktop.
Save diazvictor/a99437c5338b6e59d1477816d3168428 to your computer and use it in GitHub Desktop.
How To Create An Object With Javascript
// 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