Skip to content

Commit

Permalink
es5 basic sontructors
Browse files Browse the repository at this point in the history
added example of basic constructors in ES5
  • Loading branch information
chadsmith12 committed May 5, 2018
1 parent 51d871d commit 887b1bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions constructors-this/app.js
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);
11 changes: 11 additions & 0 deletions constructors-this/index.html
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>

0 comments on commit 887b1bf

Please sign in to comment.