<!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>
</head>
<body>
<button>点击</button>
<script>
// 1. 普通函数
function fn(){
console.log('普通函数的this' + this);
}
window.fn();
// // fn.call()
// // 2. 对象的方法 this指向的对象是o
var o = {
sayHi:function(){
console.log('对象方法的this' + this)
}
}
o.sayHi();
// // 3. 构造函数 this 指向ldh这个实例对象 原型对象里面的this指向的也是ldh这个实例对象
function Star(){ }
Star.prototype.sing = function(){
}
var ldh = new Star();
// 4. 绑定事件
JavaScript中各种函数调用方式的合集
最新推荐文章于 2022-09-08 19:23:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)