2.3 能够给jQuery添加静态方法。 javascript
var arr = new Array(3) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" document.write(arr + "<br />") document.write( + "<br />") document.write(arr) arr.push("James")
输出:java
George,John,Thomas 4 George,John,Thomas,James
function funcB(a, b) {
funcA.call(testO, a, b);
}ajax
funcB(1,2); //this变成了testO数组
咱们定义funcB函数的中,调用了funcA的call函数,这个时候咱们改变了funcA中this的指向,本来指向window的,如今指向了call的第一个参数testO这个对象。并且调用call时,由于funcA函数有两个参数,因此若是要想funcA传递参数,必须一一指出参数,即后面的两个参数a和b,或者能够只穿第一个参数app
即:funcA.call(testO);或者只传a,即:funcA.call(testO,a);async
而apply与call的区别仅在于,apply的第二个参数能够是数组形式,并且没必要一一指出参数,funcA.apply(testO,[a,b])ide
<script type="text/javascript"> function testFuc() {
alert(this.color);
}函数
$(function () {
1.testFuc(); //弹出“透明”
2.testFuc(this); //弹出“undefined”
3.testFuc.call(this.parent); //弹出“透明”
4.testFuc.call(window); //弹出“透明”
5.testFuc.call(testObj); //弹出“红色”
});
</script>post