1.箭头函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var str = 'window';
const obj={
str:'obj',
fn:()=>{
console.log(this.str);
},
fn2:function(){
console.log(this.str,'当前')
return {
str:'newObj',
fn:()=>{
console.log(this.str)
}
}
}
}
obj.newFn = ()=>{
console.log(this.str)
}
obj.fn()
obj.newFn()
var newObj = obj.fn2()
newObj.fn()
var str = 'window';
const obj={
str:'obj',
fn:function(){
console.log(this.str);
},
fn2:function(){
console.log(this.str,'当前')
return {
str:'newObj',
fn:function(){
console.log(this.str)
}
}
}
}
obj.newFn = function(){
console.log(this.str)
}
obj.fn()
obj.newFn()
var newObj = obj.fn2()
newObj.fn()
</script>
</body>
</html>