The error is actually not in the isEmpty() .
If you look at the Play Console, the compiler output will point to another place:
! @6e12h60d9 - Internal server error, for (GET) [/] -> sbt.PlayExceptions$TemplateCompilationException: Compilation error[Not parsed?] at sbt.PlayCommands$$anonfun$43.apply(PlayCommands.scala:433) ~[na:na] at sbt.PlayCommands$$anonfun$43.apply(PlayCommands.scala:409) ~[na:na] at sbt.Scoped$$anonfun$hf5$1.apply(Structure.scala:581) ~[na:na] at sbt.Scoped$$anonfun$hf5$1.apply(Structure.scala:581) ~[na:na] at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49) ~[scala-library.jar:na] at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311) ~[na:na] [warn] play - No application found at invoker init [error] C:\Users\maba\Development\play\layout\app\views\main.scala.html:14: Compilation error[Not parsed?] [error] //for(var prop in obj) { [error] ^ [error] (compile:sources) @6e12hd81d: Compilation error in C:\Users\maba\Development\play\layout\app\views\main.scala.html:14 [error] application -
Thus, it seems that the error processes the comments (I donβt know why at the moment).
So, if you want this code to run, use Play comments ( @* some comment *@ ) instead:
<script> function isEmpty(obj) { @* for(var prop in obj) { if(obj.hasOwnProperty(prop)) *@ try{ if(JSON.stringify(obj)=='{}'){ return true; }else{ return false; } }catch(e){ return false; } } </script>
source share