js返回一个匿名函数和声明一个函数后在返回有什么区别
展开全部
出错的时候看调用堆栈....
你在function 里面 throw 一个error 试试...匿名函数你怎么找 , 还是给函数命名吧
> function test(){
... return function(){
..... throw new Error("出错了")
..... }
... }
> test()()
Error: 出错了
at repl:3:7
at repl:1:8
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
> function test(){
..... return function may_throw_error(){
....... throw new Error("出错了")
....... }
..... }
undefined
> test()()
Error: 出错了
at may_throw_error (repl:3:7)
at repl:1:8
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
你在function 里面 throw 一个error 试试...匿名函数你怎么找 , 还是给函数命名吧
> function test(){
... return function(){
..... throw new Error("出错了")
..... }
... }
> test()()
Error: 出错了
at repl:3:7
at repl:1:8
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
> function test(){
..... return function may_throw_error(){
....... throw new Error("出错了")
....... }
..... }
undefined
> test()()
Error: 出错了
at may_throw_error (repl:3:7)
at repl:1:8
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询