"The new.target property allows you to determine whether a function or constructor has been called using the new operator" [1]
I can use new.target in the if statement to new.target error if the function was not called with new :
if(!new.target){ throw new Error('Must be called with new keyword!') }
However, Safari prevents the use of new.target with ! so with the error message
new.target cannot appear after prefix operator
I traced this to this line in Webkit .
However, a positive condition can be checked!
if(new.target){} else{ throw new Error('Must be called with new keyword!') }
Is this a bug with the syntax engine? Or, alternatively, should new.target be used in how they are applied?
simple playback: https://codepen.io/mdjasper/pen/eEWORY?editors=0012
Edit: this issue was filed on webkit bugzilla: https://bugs.webkit.org/show_bug.cgi?id=157970
source share