call()、apply()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>call、apply</title>
</head>
<body>
<script>
var name = "xxx";
function print(age = 1, address = "cd") {
console.log(this.name + "," + age + "," + address);
}
print();
var o = {
name: "yyy"
}
var o2 = {
name:"sss"
};
print.call(o, 22, "成都");
print.apply(o, [23, "武漢"]);
print.call(o2,24,"chengtdu");
function foo() {
console.log(this.a);
}
var a = 2;
foo.call(null);
</script>
</body>
</html>