代码拉取完成,页面将自动刷新
<!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>
<div id="app">{{finalMsg}}</div>
</body>
<script src="dist/vue.js"></script>
<script>
let vm = new Vue({
el: "#app",
data() {
return {
msg: 'monica',
}
},
computed: {
finalMsg() {
console.log('execute finalMsg()...')
return `warn: ${this.msg}`
}
}
})
console.log('vm', vm)
console.log(vm.finalMsg)
console.log(vm.finalMsg)
console.log('---')
setTimeout(() => {
vm.msg = 'eguene'
console.log(vm.finalMsg)
console.log(vm.finalMsg)
console.log('---')
}, 1000)
</script>
<script>
// function Person(id) {
// this.id = id
// //1. 在类中定义方法:每个实例都会拥有一个方法副本,内存效率低
// this.hi = function () {
// console.log('hi, this:', this);
// }
// this.hi_arrow = () => {
// console.log('hi arrow, this:', this);//Object { id: 1, hi: hi(), hi_arrow: hi_arrow() }
// }
// }
// //2. 为 Person 类的原型对象添加方法,所有实例都会共享此方法,节省内存
// Person.prototype._init = function () {
// console.log('_init, this:', this);
// }
// Person.prototype._init_arrow = () => {
// console.log('_init_arrow, this:', this);
// }
// //-----------------------------------
// let person = new Person(1);
// console.log(person);//Object { id: 1, hi: hi(), hi_arrow: hi_arrow() }
// //实例的普通方法
// person.hi();//this => Object { id: 1, hi: hi(), hi_arrow: hi_arrow() }
// console.log(new Person().hi === new Person().hi);//false
// //实例的箭头方法
// person.hi_arrow();//this => Object { id: 1, hi: hi(), hi_arrow: hi_arrow() }
// console.log(new Person().hi_arrow === new Person().hi_arrow);//false
// //原型链
// console.log(Person.prototype === new Person().__proto__);
// console.log(new Person().__proto__ === new Person().__proto__);
// console.log(Person);
// console.log(Person.prototype);//Object { _init: _init(), _init_arrow: _init_arrow(), … }
// console.log(Person.prototype.__proto__); //Person 原型 的原型:Object { … }
// console.log(Person.prototype.__proto__.__proto__); //Person 原型 的原型 的原型:null
// //原型对象的普通方法
// person._init();// this 是 person 对象
// person.__proto__._init();// this 是 Person 原型
// Person.prototype._init();// this 是 Person 原型
// //原型对象的箭头方法
// person._init_arrow();// this 是 Window 对象
// person.__proto__._init_arrow();// this 是 Window 对象
// Person.prototype._init_arrow();// this 是 Window 对象
</script>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。