为什么(/x/.test)("x")
可以正常工作,但是尝试用test
或(t=/x/.test)("x")
为t=/x/.test;t("x")
函数提供替代名称却失败了?
Firefox给了我TypeError: undefined is not a non-null object
,而Chrome给了我Uncaught TypeError: Method RegExp.prototype.test called on incompatible receiver undefined
。
我意识到(t=s=>/x/.test(s))("x")
和t=s=>/x/.test(s);t("x")
可以工作,但是我试图理解为什么上面的方法不起作用。