this和强制改变this方向 
call
格式:函数名.call();
参数: 第一个参数:传入该函数this指向的对象,传入什么强制指向什么
第二个参数开始:将原函数的参数往后顺延一位。
<script>
function show(x,y){
alert(this);
alert(x+ "," +y);
}
show.call("call",20,40);
</script>
 
apply
格式:函数名.apply()
参数:
第一个参数:传入该函数this指向的对象,传入什么强制指向什么
第二个参数:数组 数组,放入我们原有的参数
<script>
function show(x,y){
alert(this);
alert(x+ "," +y);
}
show.apply("apply",[20,40]);
</script>
 
var 关键字声明变量,将变量或者形参所在函数的大括号作为作用域处理
let 关键字是用来声明变量 只要遇到大括号就形成作用域
【注】let关键字声明的变量,所在作用域叫做块级作用域
const声明变量,变量值只能在声明的时候确定,后续是没有办法修改的
【注】const声明常量(变量没有办法改);
<script>
const IP = "127.001.33";
alert(IP);
IP = 'xx';
alert(IP);
</script>

|