14. JAVASCRIPT 保留字(1/2)
abstract arguments boolean break byte
case catch char class* const
continue debugger default delete do
double else enum* eval export*
extends* false nal nally oat
for function goto if implements
import* in instanceof int interface
15. JAVASCRIPT 保留字(2/2)
let long native new null
package private protected public return
short static super* switch synchronized
this throw throws transient true
try typeof var void volatile
while with yield
带*的保留字是 ECMAScript 5中新引入的。
31. 对象作用域(2/2)
<script>
// 全局作用域
function fn() {
// fn作用域
var max = 10;
return function bar(x) {
// bar作用域
if (x > max) {
console.log(x);
}
};
}
// 全局作用域
var f1 = fn, max = 100;
f1(15);
</script>
32. 闭包
是指有权访问另外一个函数作用域中的变量的函数。创建闭
包的常见方式就是在一个函数内部创建另外一个函数。
<script>
var arr1 = new Array(100);
for (var i = 0; i < 100; i++) {
var value1 = i;
arr1[i] = {getValue: function() {return value1;}};
}
console.log(arr1[80].getValue()); // 99(普通写法无法得到期望结果);
var arr2 = new Array(100);
for (var i = 0; i < 100; i++) {
(function() {
var value2 = i;
arr2[i] = {getValue: function() {return value2;}};
})();
}
console.log(arr2[80].getValue()); // 80(闭包写法Perfect!);
</script>
50. DOM 操作
.html() vs .text()
.append() vs .appendTo()
.prepend() vs .prependTo()
.after() vs .insertAfter()
.before() vs .insertBefore()
.replaceAll() vs .replaceWith()
.empty()
.remove()
.detach()