Javascript技巧

1
2
3
4
5
	<style style="display:block" contentEditable="true">
		body {
			background:rgb(255, 255, 255);
		}
	</style>
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
const movies = {
	list: [
		{ title: 'Heat' },
		{ title: 'Interstellar' },
		{ title: 'Savior' }
	],
	[Symbol.iterator]() {
		let index = 0;
		return {
			next: () => {
				if (index < this.list.length) {
					const value = this.list[index++].title;
					return { value, done: false };
				}
				return { done: true };
			}
		};
	}
};
 
const [, secondMovieTitle = 'NonTitle'] = movies;
console.log(secondMovieTitle);
big = {
    foo: 'value Foo',
    bar: 'value Bar'
};
var { foo = 'Unk' } = big;
console.log(foo);
var { ['foo']: name = 'Unknown' } = big;
console.log(name);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
obj1 = {
	a() {
		console.log(this);
	},
	b: 'hi',
	c: () => {
		console.log(this);
	}
};
obj1.a();
obj1.c();
A1 = function() {
	console.log(this);
};
a1 = new A1;
A1();