We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e69c63 commit a4c0e0aCopy full SHA for a4c0e0a
5-advanced-JS/starter/script.js
@@ -0,0 +1,26 @@
1
+
2
+//function constructors
3
+var Person = function(name,yearOfBirth, job){
4
+ this.name = name;
5
+ this.yearOfBirth = yearOfBirth;
6
+ this.job = job;
7
+}
8
+//Using the prototype method to include function in constructor
9
+Person.prototype.calculateAge = function(){
10
+ console.log(this.name, 'Age: ', 2016 - this.yearOfBirth);
11
12
13
+Person.prototype.lastName = 'Smith';
14
15
+// Instanciation
16
+var john = new Person('John', 1990, 'Teacher');
17
+var jane = new Person('Jane', 1969, 'designer');
18
+var mark = new Person('Mark', 1948, 'retired');
19
20
+john.calculateAge();
21
+jane.calculateAge();
22
+mark.calculateAge();
23
24
+console.log(john.lastName);
25
+console.log(jane.lastName);
26
+console.log(mark.lastName);
0 commit comments