-
Notifications
You must be signed in to change notification settings - Fork 1
/
06-object.js
53 lines (44 loc) · 1.7 KB
/
06-object.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
// call function as a constructor:
function Person(firstArgument, secondArgument){
this.name = firstArgument;
this.surname = secondArgument;
this.toString = () => {
return `${this.name} ${this.surname}`;
}
};
let jack = new Person("Jack", "Riper");
console.log(`explicit object creation from function : [${jack.name}] [${jack.surname}] ${jack.toString()}`);
let john = {
name : "John",
surname : "Lehnon",
toString : function(){
return `${this.name} ${this.surname}`;
}
};
console.log(`object: ${john}`);
let sharlize = new Object();
sharlize.name = "Sharlize";
sharlize.surname = "Theron";
sharlize.toString = ()=>`${this.name} ${this.surname}`;
console.log(`object with arrow function is not working : ${sharlize}`)
let sourceObject = {model: "2104", color: "green"}
let {model: modelFromSource, color: colorFromSource} = sourceObject;
console.log(`destructuring the object: ${modelFromSource} ${colorFromSource} `);
let {model:modelSource, color:colorSource} = sourceObject;
console.log(`destructuring the object: ${modelSource} ${colorSource} `);
let {model, color} = sourceObject;
console.log(`destructuring the object with shortcuts: ${model} ${color} `);
let {["model"]:modelByPropertyName} = sourceObject;
console.log(`destructuring the object with naming value: ${modelByPropertyName} `);
new Object(); // {}
new String(); // "", '', ``
new Number(); // 0
new Boolean(); // true/false
new Array(); // []
new RegExp(); //
new Function(); // function()/()=>
new Date(); //
console.log("Object static functions ");
console.log(`Keys: ${Object.keys(john)}`);
// console.log(`Values: ${Object.values(john)}`); ES2017 only
// console.log(`Entries: ${john.entries()}`);