个人自学前端46-function()和new function()的区别
<script>
export default {
created() {
this.test1()
this.test2()
this.test3()
},
methods: {
test1() {
// 基础用法
const a = 'a1'
function fun() {
console.log(a)
}
fun()
},
test2() {
// 同test1
const a = 'a2'
const fun = function() {
console.log(a)
}
fun()
},
test3() {
// 加new 会立刻执行
const a = 'a3'
// eslint-disable-next-line no-unused-vars
const fun = new function() {
console.log(a)
}
}
}
}
</script>
本文来自博客园,作者:暗鸦08,转载请注明原文链接:https://www.cnblogs.com/DarkCrow/p/17094151.html

浙公网安备 33010602011771号