Skip to content

Commit 09555cf

Browse files
committed
feat: new.target
1 parent 77ff09e commit 09555cf

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • JS/function/construct-func

JS/function/construct-func/new.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function newTarget() {
2+
if (new.target) {
3+
console.log('正确的通过 new 调用')
4+
console.log(new.target)
5+
} else {
6+
console.log('使用方法错误,应该用 new')
7+
return
8+
}
9+
}
10+
11+
newTarget()
12+
new newTarget()
13+
/*
14+
使用方法错误,应该用 new
15+
正确的通过 new 调用
16+
[Function: newTarget]
17+
*/

0 commit comments

Comments
 (0)