-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsample006.html
21 lines (17 loc) · 913 Bytes
/
sample006.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html><html lang="en"><body><script>
/* Person is a constructor function. It was written with the intent of being used with the new keyword. */
var Person = function Person(living, age, gender) {
// "this" below is the new object that is being created (i.e. this = new Object();)
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function () { return this.gender; };
// when the function is called with the new keyword "this" is returned instead of false
};
// instantiate a Person object named cody
var cody = new Person(true, 33, 'male');
// cody is an object and an instance of Person()
console.log(typeof cody); // logs object
console.log(cody); // logs the internal properties and values of cody
console.log(cody.constructor); // logs the Person() function
</script></body></html>