-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecma-5.js
35 lines (29 loc) · 936 Bytes
/
ecma-5.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
function createAnimal(name, owner) {
return {
name,
owner,
getInfo(){
return `${this.name} is owned by ${this.owner}`
},
address: {
street: '123 Main St',
city: 'Beijing'
}
}
}
var spot = createAnimal("Spot", "Doug");
document.write(`${spot.getInfo()}<br />`)
document.write(`${spot.name} is at ${spot.address.street}<br />`)
document.write(`${Object.getOwnPropertyNames(spot).join(" ")}<br />`)
let {name, owner} = spot;
document.write(`Name : ${name} Owner : ${owner}<br />`);
let {address} = spot;
document.write(`Address : ${address.street}<br />`);
let favNums = [2.718, .5772, 4.6692];
let[,,chaos] = favNums;
document.write(`Chaos : ${chaos}<br />`);
let [, ...last2] = favNums;
document.write(`2nd Num : ${last2}<br />`);
let val1 = 1, val2 = 2;
[val1, val2] = [val2, val1];
document.write(`Val2 : ${val2} Val1 : ${val1}<br />`);