62 lines
1.4 KiB
HTML
62 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Document</title>
|
||
<script>
|
||
// "use strict";
|
||
// this
|
||
// 1. 谁调用 就指向谁 指向目标是一个对象
|
||
// 2. 如果没有对象调用他 就指向全局对象(window)
|
||
var a=1
|
||
// var name;
|
||
// console.log(a)
|
||
// console.log(window.a)
|
||
// console.log(this.a) //1
|
||
// var name="华晨宇"
|
||
var obj={
|
||
name:"asd",
|
||
echoname:function(){
|
||
console.log(this.name)
|
||
}
|
||
}
|
||
// obj.echoname()
|
||
|
||
function a(){
|
||
var user = "追梦子";
|
||
console.log(this.user);
|
||
console.log(this); // window
|
||
}
|
||
// a();
|
||
|
||
function myFunction() {
|
||
"use strict";
|
||
console.log(this);
|
||
}
|
||
// myFunction()
|
||
// function fnza(){
|
||
// console.log(this.name)
|
||
// }
|
||
// fnza()
|
||
// fnza.name="asd"
|
||
// window.name="qwe"
|
||
// console.log(fnza.name)
|
||
|
||
|
||
function foo() {
|
||
console.log( this.a ,"jkjkjkjkjk");
|
||
}
|
||
var obj = {
|
||
a: 2,
|
||
foo: foo
|
||
};
|
||
var a = "xxxxx"
|
||
setTimeout( obj.foo ,100);
|
||
</script>
|
||
</head>
|
||
<body>
|
||
|
||
</body>
|
||
</html> |