-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstructors.js
72 lines (57 loc) · 1.73 KB
/
constructors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let normal = normalFunction(1,2);
function normalFunction(arg1,arg2){
this.arg1 = arg1;
this.arg2 = arg2;
console.log("I am a normal Function");
}
function objectConstructor(arg1,arg2){
this.arg1 = arg1;
this.arg2 = arg2;
console.log("Object Constructed");
}
function createObject(arg1,arg2){
let returnObject = {}
returnObject.arg1 = arg1;
returnObject.arg2 = arg2;
return returnObject;
}
let objectC = new objectConstructor(1,2);
let objectD = new objectConstructor(3,5);
let createdObject = createObject(5,6);
console.log(createdObject);
console.log(objectC.constructor == objectD.constructor);
console.log(typeof createdObject);
console.log(typeof objectC);
// console.log(normal.args1);
// function Book() {
// }
var myBook = new Book();
myBook instanceof Book // true
console.log(myBook instanceof Object) // false
myBook.constructor === Book;
function Book(name, year) {
this.name = name;
this.year = '(' + year + ')';
}
var firstBook = new Book("Pro AngularJS", 2014);
var secondBook = new Book("Secrets Of The JavaScript Ninja", 2013);
var thirdBook = new Book("JavaScript Patterns", 2010);
var testStringObject = new String("string");
console.log(testStringObject);
// function Human(firstName, lastName) {
// this.firstName = firstName,
// this.lastName = lastName,
// this.fullName = function() {
// return this.firstName + " " + this.lastName;
// }
// }
function Human(firstName, lastName) {
this.firstName = firstName,
this.lastName = lastName
}
Human.prototype.fullName = function(){
console.log(this.firstName + " " + this.lastName);
}
var person1 = new Human("Ghino", "Punzalan");
var person2 = new Human("Sachin", "Tendulkar");
person1.fullName(); // Ghino Punzalan