<!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></body>
<script>
// apply call bind this是可以被改变的
function User(name) {
this.name = name;
}
let lisi = new User("李四");
console.log(lisi); //User {name: '李四'}
let cms = { url: "cms.com" };
User.call(cms, "管理系统");
console.log(cms); //{url: 'cms.com', name: '管理系统'}
</script>
</html>
js this构造函数原理
最新推荐文章于 2024-07-23 11:32:13 发布