-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added example of basic constructors in ES5
- Loading branch information
1 parent
51d871d
commit 887b1bf
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Constructors and this keyword in ES5 | ||
* Demonstrates a constructor using ES5 and and the this keyword. | ||
*/ | ||
|
||
// Person Constructor | ||
function Person(name, dob) { | ||
this.name = name; | ||
this.birthday = new Date(dob); | ||
this.getAge = function() { | ||
const dateDiff = Date.now() - this.birthday.getTime(); | ||
const ageDate = new Date(dateDiff); | ||
|
||
return Math.abs(ageDate.getUTCFullYear() - 1970); | ||
} | ||
} | ||
|
||
const me = new Person("Chad", '2-12-1990'); | ||
console.log(me); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Sandbox</title> | ||
</head> | ||
<body> | ||
<script src="app.js"></script> | ||
</body> | ||
</html> |