Getting an exception compiling

11 views
Skip to first unread message

Gopalan Suresh Raj

unread,
Nov 5, 2009, 1:54:21 PM11/5/09
to Closure Compiler Discuss
How do I report problems?

I get an internal compiler error while compiling javascript code from
http://closure-compiler.appspot.com/home.

I would be glad to pass on the original source if you tell me how to
post it to you

Cheers
Gopalan.

23: java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.
Conflicting externs name: {SyntheticVarsDeclar}
Node: Input_0:358:8
hanoi(disc-1, source, destination, auxillary);
Parent: Input_0:358:13
hanoi(disc-1, source, destination, auxillary);

at com.google.javascript.jscomp.Compiler.newExternInput(Compiler.java:
900)
at com.google.javascript.jscomp.VarCheck.getSynthesizedExternsInput
(VarCheck.java:192)
at com.google.javascript.jscomp.VarCheck.getSynthesizedExternsRoot
(VarCheck.java:201)
at com.google.javascript.jscomp.VarCheck.visit(VarCheck.java:124)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:463)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseFunction
(NodeTraversal.java:490)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:448)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseBranch
(NodeTraversal.java:456)
at com.google.javascript.jscomp.NodeTraversal.traverseRoots
(NodeTraversal.java:271)
at com.google.javascript.jscomp.NodeTraversal.traverseRoots
(NodeTraversal.java:421)
at com.google.javascript.jscomp.VarCheck.process(VarCheck.java:83)
at com.google.javascript.jscomp.Compiler.process(Compiler.java:670)
at com.google.javascript.jscomp.Compiler.sanityCheckVars
(Compiler.java:1489)
at com.google.javascript.jscomp.Compiler.optimize(Compiler.java:1469)
at com.google.javascript.jscomp.Compiler.compileInternal
(Compiler.java:555)
at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:65)
at com.google.javascript.jscomp.Compiler$1.call(Compiler.java:462)
at com.google.javascript.jscomp.Compiler$1.call(Compiler.java:460)
at com.google.javascript.jscomp.Compiler$2.run(Compiler.java:494)
at com.google.javascript.jscomp.Compiler.runInCompilerThread
(Compiler.java:517)
at com.google.javascript.jscomp.Compiler.compile(Compiler.java:460)
at com.google.javascript.jscomp.Compiler.compile(Compiler.java:429)
at
com.google.javascript.jscomp.webservice.backend.CompilerInvokerImpl.compile
(CompilerInvokerImpl.java:54)
at
com.google.javascript.jscomp.webservice.backend.ServerController.executeRequest
(ServerController.java:179)
at
com.google.javascript.jscomp.webservice.backend.CompilationRequestHandler.service
(CompilationRequestHandler.java:122)
at
com.google.javascript.jscomp.webservice.backend.CompilationRequestHandler.service
(CompilationRequestHandler.java:102)
at
com.google.javascript.jscomp.webservice.frontend.CompilationServlet.doPost
(CompilationServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1093)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter
(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1084)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle
(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle
(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle
(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle
(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle
(AppVersionHandlerMap.java:238)
at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete
(HttpConnection.java:830)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable
(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at
com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest
(JettyServletEngineAdapter.java:139)
at com.google.apphosting.runtime.JavaRuntime.handleRequest
(JavaRuntime.java:239)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime
$6.handleBlockingRequest(RuntimePb.java:5135)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime
$6.handleBlockingRequest(RuntimePb.java:5133)
at com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest
(BlockingApplicationHandler.java:24)
at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:
363)
at com.google.net.rpc.impl.Server$2.run(Server.java:814)
at com.google.tracing.LocalTraceSpanRunnable.run
(LocalTraceSpanRunnable.java:56)
at com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan
(LocalTraceSpanBuilder.java:516)
at com.google.net.rpc.impl.Server.startRpc(Server.java:769)
at com.google.net.rpc.impl.Server.processRequest(Server.java:351)
at com.google.net.rpc.impl.ServerConnection.messageReceived
(ServerConnection.java:437)
at com.google.net.rpc.impl.RpcConnection.parseMessages
(RpcConnection.java:319)
at com.google.net.rpc.impl.RpcConnection.dataReceived
(RpcConnection.java:290)
at com.google.net.async.Connection.handleReadEvent(Connection.java:
436)
at com.google.net.async.EventDispatcher.processNetworkEvents
(EventDispatcher.java:762)
at com.google.net.async.EventDispatcher.internalLoop
(EventDispatcher.java:207)
at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:
101)
at com.google.net.rpc.RpcService.runUntilServerShutdown
(RpcService.java:251)
at com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run
(JavaRuntime.java:396)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Conflicting externs
name: {SyntheticVarsDeclar}
... 76 more

Original Post Data:
output_format=json&output_info=compiled_code&output_info=warnings&output_info=errors&output_info=statistics&compilation_level=ADVANCED_OPTIMIZATIONS&warning_level=verbose&formatting=pretty_print&formatting=print_input_delimiter&output_file_name=default.js&js_code=
%2F*%20%0A%20*%20To%20change%20this%20template%2C%20choose%20Tools
%20%7C%20Templates%0A%20*%20and%20open%20the%20template%20in%20the
%20editor.%0A%20*%2F%0Adocument.writeln(%22Hello%2C%20Gopalan%20Suresh
%20Raj%22)%3B%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-
%20Objects%20-%20Object%20Literals%22)%3B%0Adocument.writeln(%22%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0Avar%20empty_object
%20%3D%20%7B%7D%3B%0Avar%20stooge%20%3D%20%7B%0A%20%20%20%20%22first-
name%22%3A%22Gopalan%22%2C%0A%20%20%20%20%22middle-name%22%3A%22Suresh
%22%2C%0A%20%20%20%20%22last-name%22%3A%22Raj%22%0A%7D%3B
%0Adocument.writeln(%22stooge%5B%5C%22FIRST-NAME%5C%22%5D%3D
%20%22%2Bstooge%5B%22FIRST-NAME%22%5D)%3B%0Adocument.writeln(%22stooge
%5B%5C%22middle-name%5C%22%5D%3D%20%22%2Bstooge%5B%22middle-name%22%5D)
%3B%0A%0Avar%20flight%20%3D%20%7B%0A%20%20%20%20airline%3A%20%22Oceanic
%22%2C%0A%20%20%20%20number%3A%20815%2C%0A%20%20%20%20departure%3A
%20%7B%0A%20%20%20%20%20%20%20%20IATA%3A%20%22MAS%22%2C%0A
%20%20%20%20%20%20%20%20time%3A%20%222009-09-22%2014%3A55%22%2C%0A
%20%20%20%20%20%20%20%20city%3A%20%22Chennai%22%0A%20%20%20%20%7D%2C%0A
%20%20%20%20arrival%3A%20%7B%0A%20%20%20%20%20%20%20%20IATA%3A%20%22LAX
%22%2C%0A%20%20%20%20%20%20%20%20time%3A
%20%222009-09-23%2010%3A42%22%2C%0A%20%20%20%20%20%20%20%20city%3A
%20%22Los%20Angeles%22%0A%20%20%20%20%7D%0A%7D%3B%0A%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B
%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-%20Objects%20-
%20Retrieval%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0Adocument.writeln(%22flight.status%3D
%20%22%2Bflight.status)%3B%0A%0Avar%20nickname%20%3D%20stooge%5B
%22nick-name%22%5D%20%7C%7C%20%22(none)%22%3B%0Adocument.writeln
(%22nickname%3D%20%22%2Bnickname)%3B%0Avar%20status%20%3D
%20flight.status%20%7C%7C%20%22unknown%22%3B%0Adocument.writeln
(%22status%3D%20%22%2Bstatus)%3B%0A%0Avar%20theEquipment%20%3D
%20flight.equipment%3B%0Adocument.writeln(%22flight.equipment%3D
%20%22%2Bflight.equipment)%3B%0A%0A%2F%2Fvar%20theModel%20%3D
%20flight.equipment.model%3B%0A%2F%2Fdocument.writeln(theModel)%3B%0A
%2F%2F%0A%2F%2Fvar%20theCombo%20%3D%20flight.equipment
%20%26%26%20flight.equipment.model%3B%0A%2F%2Fdocument.writeln
(theCombo)%3B%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-
%20Objects%20-%20Update%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0Astooge%5B%22other-name%22%5D%20%3D
%20%22Suresh%20Raj%20Gopalan%22%3B%0Adocument.writeln(%22stooge%5B%5C
%22other-name%5C%22%5D%3D%20%22%2Bstooge%5B%22other-name%22%5D)%3B
%0Astooge.nickname%20%3D%20%22Suresh%22%3B%0Adocument.writeln
(%22stooge.nickname%3D%20%22%2Bstooge.nickname)%3B%0Aflight.equipment
%20%3D%20%7B%0A%20%20%20%20model%20%3A%20'Boeing%20777'%0A%7D%3B
%0Adocument.writeln(%22flight.equipment.model%3D
%20%22%2Bflight.equipment.model)%3B%0Aflight.status%20%3D
%20'overdue'%3B%0Adocument.writeln(%22flight.status%3D
%20%22%2Bflight.status)%3B%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0Adocument.writeln(%22%2F%2F
%20Chapter%203%20-%20Objects%20-%20Reference%22)%3B%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0Avar%20x%20%3D
%20stooge%3B%0Adocument.writeln(%22x%3D%20%22%2Bx)%3B%0Ax.nickname
%20%3D%20%22The%20Raj%22%3B%0Adocument.writeln(%22x.nickname%3D
%20%22%2Bx.nickname)%3B%0Avar%20nick%20%3D%20stooge.nickname%3B
%0Adocument.writeln(%22nick%3D%20%22%2Bnick)%3B%0A%0Avar%20a%20%3D
%20%7B%0A%20%20%20%20value%3A%22a%22%0A%7D%2C%20b%20%3D%20%7B%0A
%20%20%20%20value%3A%22b%22%0A%7D%2C%20c%20%3D%20%7B%0A
%20%20%20%20value%3A%22c%22%0A%7D%3B%0Adocument.writeln(%22a.value%3D
%20%22%2Ba.value)%3B%0Adocument.writeln(%22b.value%3D%20%22%2Bb.value)
%3B%0Adocument.writeln(%22c.value%3D%20%22%2Bc.value)%3B%0A%0Aa%20%3D
%20b%20%3D%20c%20%3D%20%7B%0A%20%20%20%20value%3A%22common%20d%22%0A%7D
%3B%0Adocument.writeln(%22a.value%3D%20%22%2Ba.value)%3B
%0Adocument.writeln(%22b.value%3D%20%22%2Bb.value)%3B
%0Adocument.writeln(%22c.value%3D%20%22%2Bc.value)%3B%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-%20Objects%20-
%20Prototype%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0Aif(typeof%20Object.create%20!%3D%3D
%20'function')%20%7B%0A%20%20%20%20Object.create%20%3D%20function
(anObject)%20%7B%0A%20%20%20%20%20%20%20%20var%20aFunctionVariable
%20%3D%20function()%20%7B%7D%3B%0A
%20%20%20%20%20%20%20%20aFunctionVariable.prototype%20%3D%20anObject%3B
%0A%20%20%20%20%20%20%20%20return%20new%20aFunctionVariable()%3B%0A
%20%20%20%20%7D%3B%0A%7D%0Avar%20another_stooge%20%3D%20Object.create
(stooge)%3B%0Aanother_stooge%5B'first-name'%5D%20%3D%20'Suresh'%3B
%0Adocument.writeln(%22another_stooge%5B'first-name'%5D%3D
%20%22%2Banother_stooge%5B'first-name'%5D)%3B%0Aanother_stooge
%5B'middle-name'%5D%20%3D%20'Raj'%3B%0Adocument.writeln
(%22another_stooge%5B'middle-name'%5D%3D%20%22%2Banother_stooge
%5B'middle-name'%5D)%3B%0Aanother_stooge.nickname%20%3D%20'Raj'%3B
%0Adocument.writeln(%22another_stooge.nickname%3D
%20%22%2Banother_stooge.nickname)%3B%0A%0Astooge.profession%20%3D
%20'actor'%3B%0Adocument.writeln(%22stooge.profession%3D
%20%22%2Bstooge.profession)%3B%0Adocument.writeln
(%22another_stooge.profession%3D%20%22%2Banother_stooge.profession)%3B
%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-%20Objects%20-
%20Reflection%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0A%0Adocument.writeln(%22typeof
%20flight.number%3D%20%22%2Btypeof%20flight.number)%3B
%0Adocument.writeln(%22typeof%20flight.status%3D%20%22%2Btypeof
%20flight.status)%3B%0Adocument.writeln(%22typeof%20flight.arrival%3D
%20%22%2Btypeof%20flight.arrival)%3B%0Adocument.writeln(%22typeof
%20flight.manifest%3D%20%22%2Btypeof%20flight.manifest)%3B%0A
%0Adocument.writeln(%22typeof%20flight.toString%3D%20%22%2Btypeof
%20flight.toString)%3B%0Adocument.writeln(%22typeof
%20flight.constructor%3D%20%22%2Btypeof%20flight.constructor)%3B%0A
%0Adocument.writeln(%22flight.hasOwnProperty('number')%3D
%20%22%2Bflight.hasOwnProperty('number'))%3B%0Adocument.writeln
(%22flight.hasOwnProperty('constructor')%3D
%20%22%2Bflight.hasOwnProperty('constructor'))%3B%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-%20Objects%20-
%20Enumeration%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0A%0Avar%20attribute%3B%0Afor(attribute%20in
%20another_stooge)%20%7B%0A%20%20%20%20if(typeof%20another_stooge
%5Battribute%5D%20!%3D%3D%20'function')%20%7B%0A
%20%20%20%20%20%20%20%20document.writeln(attribute
%2B'%3A'%2Banother_stooge%5Battribute%5D)%3B%0A%20%20%20%20%7D%0A%7D%0A
%0Avar%20index%3B%0Avar%20properties%20%3D%20%5B%0A'first-name'%2C
%0A'middle-name'%2C%0A'last-name'%2C%0A'profession'%0A%5D%3B%0Afor
(index%20%3D%200%3B%20index%20%3C%20properties.length%3B%20index%20%2B
%3D%201)%20%7B%0A%20%20%20%20document.writeln(properties%5Bindex%5D
%20%2B%20%22%3A%22%20%2B%20another_stooge%5Bproperties%5Bindex%5D%5D)
%3B%0A%7D%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-
%20Objects%20-%20Delete%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0Adocument.writeln
(%22another_stooge.nickname%3D%20%22%2Banother_stooge.nickname)%3B
%0Adelete%20another_stooge.nickname%3B%0Adocument.writeln
(%22another_stooge.nickname%3D%20%22%2Banother_stooge.nickname)%3B%0A
%0A%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%203%20-%20Objects%20-
%20Global%20Abatement%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20MYAPP
%20%3D%20%7B%7D%3B%0A%0AMYAPP.stooge%20%3D%20%7B%0A
%20%20%20%20%22first-name%22%20%3A%20%22Gopalan%22%2C%0A
%20%20%20%20%22middle-name%22%20%3A%20%22Suresh%22%2C%0A
%20%20%20%20%22last-name%22%20%3A%20%22Raj%22%0A%7D%3B%0A
%0Adocument.writeln(%22MYAPP.stooge%5B%5C%22first-name%5C%22%5D%3D
%20%22%2BMYAPP.stooge%5B%22first-name%22%5D)%3B%0Adocument.writeln
(%22MYAPP.stooge%5B%5C%22middle-name%5C%22%5D%3D%20%22%2BMYAPP.stooge
%5B%22middle-name%22%5D)%3B%0Adocument.writeln(%22MYAPP.stooge%5B%5C
%22last-name%5C%22%5D%3D%20%22%2BMYAPP.stooge%5B%22last-name%22%5D)%3B
%0A%0AMYAPP.flight%20%3D%20%7B%0A%20%20%20%20airline%20%3A%20%22Oceanic
%22%2C%0A%20%20%20%20number%20%3A%20815%2C%0A%20%20%20%20departure
%20%3A%20%7B%0A%20%20%20%20%20%20%20%20IATA%20%3A%20%22MAA%22%2C%0A
%20%20%20%20%20%20%20%20time%20%3A%20%222009-09-22%2014%3A55%22%2C%0A
%20%20%20%20%20%20%20%20city%20%3A%20%22Chennai%22%0A%20%20%20%20%7D%2C
%0A%20%20%20%20arrival%20%3A%20%7B%0A%20%20%20%20%20%20%20%20IATA%20%3A
%20%22LAX%22%2C%0A%20%20%20%20%20%20%20%20time%20%3A
%20%222009-09-23%2010%3A42%22%2C%0A%20%20%20%20%20%20%20%20city%20%3A
%20%22Los%20Angeles%22%0A%20%20%20%20%7D%0A%7D%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Function%20Literal%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20add%20%3D
%20function(a%2C%20b)%20%7B%0A%20%20%20%20return%20a%20%2B%20b%3B%0A%7D
%3B%0Avar%20total%20%3D%20add(7%2C3)%3B%0Adocument.writeln(%22add
(7%2C3)%3D%20%22%2Btotal)%3B%0A%2F%2F
%20-------------------------------------------------%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Method%20Invocation%20Pattern%22)%3B%0Adocument.writeln(%22%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20myObject
%20%3D%20%7B%0A%20%20%20%20value%20%3A%200%2C%0A%20%20%20%20increment
%20%3A%20function(anIncrement)%20%7B%0A
%20%20%20%20%20%20%20%20this.value%20%2B%3D%20(typeof%20anIncrement
%20%3D%3D%3D%20'number')%20%3F%20anIncrement%20%3A%201%3B%0A
%20%20%20%20%7D%0A%7D%3B%0AmyObject.increment()%3B%0Adocument.writeln
(%22myObject.increment()%3D%20%22%2BmyObject.value%2B%22%20is%20the
%20value%20of%20myObject.value%22)%3B%0A%0AmyObject.increment(2)%3B
%0Adocument.writeln(%22myObject.increment(2)%3D%20%22%2BmyObject.value
%2B%22%20is%20the%20value%20of%20myObject.value%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Function%20Invocation%20Pattern%22)%3B%0Adocument.writeln(%22%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20sum%20%3D
%20add(9%2C1)%3B%0Adocument.writeln(%22add(9%2C1)%3D%20%22%2Bsum)%3B%0A
%0A%2F%2F%20-------------------------------------------------
%0AmyObject.myDouble%20%3D%20function()%20%7B%0A%20%20%20%20var%20that
%20%3D%20this%3B%20%2F%2F%20workaround%0A%20%20%20%20var%20helper%20%3D
%20function()%20%7B%0A%20%20%20%20%20%20%20%20that.value%20%3D%20add
(that.value%2C%20that.value)%3B%0A%20%20%20%20%7D%3B%0A
%20%20%20%20helper()%3B%20%2F%2F%20Invoke%20helper%20as%20a%20function
%0A%7D%3B%0AmyObject.myDouble()%3B%0Adocument.writeln
(%22myObject.myDouble()%3D%20%22%2BmyObject.value%2B%22%20is%20the
%20value%20of%20myObject.value%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Constructor%20Invocation%20Pattern%20%22)%3B%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20Quote
%20%3D%20function(aString)%20%7B%0A%20%20%20%20this.status%20%3D
%20aString%3B%0A%7D%3B%0AQuote.prototype.get_status%20%3D%20function()
%20%7B%0A%20%20%20%20return%20this.status%3B%0A%7D%0Avar%20myQuote
%20%3D%20new%20Quote(%22confused!!!%22)%3B%0Adocument.writeln
(%22myQuote.get_status()%3D%20%22%2BmyQuote.get_status())%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Apply%20Invocation%20Pattern%22)%3B%0Adocument.writeln(%22%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20array
%20%3D%20%5B6%2C4%5D%3B%0Avar%20aSum%20%3D%20add.apply(null%2C%20array)
%3B%0Adocument.writeln(%22add.apply(null%2C%20array)%3D%20%22%2BaSum)
%3B%0A%0A%2F%2F%20-------------------------------------------------
%0Avar%20statusObject%20%3D%20%7B%0A%20%20%20%20status%20%3A%20'A-
OK'%0A%7D%3B%0Avar%20aStatus%20%3D%20Quote.prototype.get_status.apply
(statusObject)%3B%0Adocument.writeln
(%22Quote.prototype.get_status.apply(statusObject)%3D%20%22%2BaStatus)
%3B%0A%2F%2F%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Arguments%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20arraySum
%20%3D%20function()%20%7B%0A%20%20%20%20var%20index%2C%20theArraySum
%20%3D%200%3B%0A%20%20%20%20for(index%20%3D%200%3B%20index%20%3C
%20arguments.length%3B%20index%20%2B%3D%201)%20%7B%0A
%20%20%20%20%20%20%20%20theArraySum%20%2B%3D%20arguments%5Bindex%5D%3B
%0A%20%20%20%20%7D%0A%20%20%20%20return%20theArraySum%3B%0A%7D%3B
%0Adocument.writeln(%22arraySum(4%2C8%2C12%2C16%2C20%2C24%2C28)%3D
%20%22%2BarraySum(4%2C8%2C12%2C16%2C20%2C24%2C28))%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20safeAdd
%20%3D%20function(a%2C%20b)%20%7B%0A%20%20%20%20if(typeof%20a%20!%3D%3D
%20'number'%20%7C%7C%20typeof%20b%20!%3D%3D%20'number')%20%7B%0A
%20%20%20%20%20%20%20%20throw%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20name%20%3A%20'TypeError'%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20message%20%3A%20'safeAdd%20needs
%20numbers'%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%7D%0A
%20%20%20%20return%20a%20%2B%20b%3B%0A%7D%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20trySafeAdd
%20%3D%20function()%20%7B%0A%20%20%20%20try%20%7B%0A
%20%20%20%20%20%20%20%20safeAdd(%22seven%22)%3B%0A%20%20%20%20%7D
%20catch(exception)%20%7B%0A%20%20%20%20%20%20%20%20document.writeln
(%22Exception%20from%20trySafeAdd%22)%3B%0A
%20%20%20%20%20%20%20%20document.writeln(exception.name%20%2B%20'%20%3A
%20'%20%2B%20exception.message)%3B%0A%20%20%20%20%7D%0A%7D%3B
%0AtrySafeAdd()%3B%0A%2F%2F
%20-------------------------------------------------%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Augmenting%20Types%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------
%0AFunction.prototype.method%20%3D%20function(name%2C%20aFunction)
%20%7B%0A%20%20%20%20if(!this.prototype%5Bname%5D)%20%7B%0A
%20%20%20%20%20%20%20%20this.prototype%5Bname%5D%20%3D%20aFunction%3B
%0A%20%20%20%20%7D%0A%20%20%20%20return%20this%3B%0A%7D%3B
%0ANumber.method('integer'%2C%0A%20%20%20%20function()%20%7B%0A
%20%20%20%20%20%20%20%20return%20Math%5B(this%20%3C
%200)%3F'ceil'%3A'floor'%5D(this)%3B%0A%20%20%20%20%7D%0A
%20%20%20%20)%3B%0Adocument.writeln(%22(-10%2F3).integer()%3D%20%22%2B
(-10%2F3).integer())%3B%0A%0A%2F%2F
%20-------------------------------------------------%0AString.method
('trim'%2C%0A%20%20%20%20function()%20%7B%0A%20%20%20%20%20%20%20%20var
%20regularExpression%20%3D%20%2F%5E%5Cs%2B%7C%5Cs%2B%24%2Fg%3B%0A
%20%20%20%20%20%20%20%20return%20this.replace(regularExpression%2C
%20'')%3B%0A%20%20%20%20%7D%0A%20%20%20%20)%3B%0Adocument.writeln
('%22'%2B%20%22%20%20%20%20%20%20neat!%20%20%20%20%22.trim()%2B'%22')
%3B%0A%2F%2F%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Recursion%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20hanoi
%20%3D%20function%20hanoi(disc%2C%20source%2C%20auxillary%2C
%20destination)%20%7B%0A%20%20%20%20if(disc%20%3E%200)%20%7B%0A
%20%20%20%20%20%20%20%20hanoi(disc-1%2C%20source%2C%20destination%2C
%20auxillary)%3B%0A%20%20%20%20%20%20%20%20document.writeln('Move
%20disc%23%20'%2Bdisc%2B'%20from%20'%2Bsource%2B'%20to%20'%2B
%20destination)%3B%0A%20%20%20%20%20%20%20%20hanoi(disc-1%2C
%20auxillary%2C%20source%2C%20destination)%3B%0A%20%20%20%20%7D%0A%7D
%3B%0Ahanoi(3%2C%20'Source'%2C%20'Auxillary'%2C%20'Destination')%3B%0A
%0A%2F%2F%20-------------------------------------------------%0Avar
%20walk_the_DOM%20%3D%20function%20walk(node%2C%20aFunction)%20%7B%0A
%20%20%20%20aFunction(node)%3B%0A%20%20%20%20node%20%3D
%20node.firstChild%3B%0A%20%20%20%20while(node)%20%7B%0A
%20%20%20%20%20%20%20%20walk(node%2C%20aFunction)%3B%0A
%20%20%20%20%20%20%20%20node%20%3D%20node.nextSibling%3B%0A
%20%20%20%20%7D%0A%7D%3B%0Avar%20getElementsByAttribute%20%3D
%20function(anAttribute%2C%20value)%20%7B%0A%20%20%20%20var%20results
%20%3D%20%5B%5D%3B%0A%20%20%20%20walk_the_DOM(document.body%2C%0A
%20%20%20%20%20%20%20%20function(node)%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20var%20actual%20%3D%20node.nodeType
%20%3D%3D%3D%201%20%26%26%20node.getAttribute(anAttribute)%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20if(%20(typeof%20actual%20%3D%3D%3D
%20'string')%20%26%26%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20((actual%20%3D%3D%3D
%20value)%20%7C%7C%20(typeof%20value%20!%3D%3D%20'string'))%20)%20%7B
%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20results.push(node)
%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A
%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%3B%0A
%20%20%20%20return%20results%3B%0A%7D%3B%0Avar%20theAttributes%20%3D
%20getElementsByAttribute('src')%3B%0Afor(value%20in%20theAttributes)
%20%7B%0A%20%20%20%20document.writeln(value)%3B%0A%7D%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20factorial
%20%3D%20function%20factorial(theNumber%2C%20index)%20%7B%0A
%20%20%20%20index%20%3D%20index%20%7C%7C%201%3B%0A%20%20%20%20if
(theNumber%20%3C%202)%20%7B%0A%20%20%20%20%20%20%20%20return%20index%3B
%0A%20%20%20%20%7D%0A%20%20%20%20return%20factorial(theNumber-1%2C
%20theNumber*index)%3B%0A%7D%3B%0Adocument.writeln(%22factorial(10)%3D
%20%22%2Bfactorial(10))%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Scope%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar
%20fooFunction%20%3D%20function()%20%7B%0A%20%20%20%20var%20a%20%3D
%203%2C%20b%20%3D%205%3B%0A%20%20%20%20document.writeln(%22Inside
%20fooFunction%20(after%20a%20%3D%203%2C%20b%20%3D%205)%2C%20a%20%3D
%20%22%2Ba%2B%22%2C%20b%20%3D%20%22%2Bb)%3B%0A%20%20%20%20var
%20barFunction%20%3D%20function()%20%7B%0A%20%20%20%20%20%20%20%20var
%20b%20%3D%207%2C%20e%20%3D%2011%3B%0A
%20%20%20%20%20%20%20%20document.writeln(%22Inside%20barFunction%20
(after%20b%20%3D%207%2C%20c%20%3D%2011)%2C%20a%20%3D%20%22%2Ba%2B%22%2C
%20b%20%3D%20%22%2Bb%2B%22%2C%20e%20%3D%20%22%2Be)%3B%0A
%20%20%20%20%20%20%20%20a%20%2B%3D%20b%20%2B%20e%3B%0A
%20%20%20%20%20%20%20%20document.writeln(%22Inside%20barFunction%20
(after%20a%20%2B%3D%20b%20%2B%20c)%2C%20a%20%3D%20%22%2Ba%2B%22%2C%20b
%20%3D%20%22%2Bb%2B%22%2C%20e%20%3D%20%22%2Be)%3B%0A%20%20%20%20%7D%3B
%0A%20%20%20%20document.writeln(%22Inside%20fooFunction%20(after%20a
%20%3D%203%2C%20b%20%3D%205)%2C%20a%20%3D%20%22%2Ba%2B%22%2C%20b%20%3D
%20%22%2Bb)%3B%0A%20%20%20%20barFunction()%3B%0A
%20%20%20%20document.writeln(%22Inside%20fooFunction%20(after
%20invoking%20barFunction()%2C%20a%20%3D%20%22%2Ba%2B%22%2C%20b%20%3D
%20%22%2Bb)%3B%0A%7D%3B%0AfooFunction()%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Closure%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20someObject
%20%3D%20function()%20%7B%0A%20%20%20%20var%20value%20%3D%200%3B%0A
%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20increment%3A
%20function(anIncrement)%20%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20value%20%2B%3D%20(typeof
%20anIncrement%20%3D%3D%3D%20'number')%3FanIncrement%20%3A%201%3B%0A
%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20getValue%3A
%20function()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return
%20value%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3B%0A%7D()
%3B%0AsomeObject.increment(9)%3B%0AsomeObject.increment(1)%3B
%0Adocument.writeln(%22someObject.increment(9)%3D
%20%22%2BsomeObject.getValue()%2B%22%20is%20the%20value%20of
%20someObject.getValue()%22)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20someQuote
%20%3D%20function(status)%20%7B%0A%20%20%20%20return%20%7B%0A
%20%20%20%20%20%20%20%20get_status%3A%20function()%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20return%20status%3B%0A
%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3B%0A%7D%3B%0Avar
%20mySomeQuote%20%3D%20someQuote('amazed!')%3B%0Adocument.writeln
(%22someQuote('amazed!')%3D%20%22%2BmySomeQuote.get_status()%2B%22%20is
%20the%20value%20of%20mySomeQuote.get_status()%22)%3B%0A%0A%0A%2F%2F
%20-------------------------------------------------%0Avar%20fade%20%3D
%20function(node)%20%7B%0A%20%20%20%20var%20level%20%3D%201%3B%0A
%20%20%20%20var%20stepExpressionToRun%20%3D%20function()%20%7B%0A
%20%20%20%20%20%20%20%20var%20hex%20%3D%20level.toString(16)%3B%0A
%20%20%20%20%20%20%20%20node.style.backgroundColor%20%3D
%20'%23FFFF'%2Bhex%2Bhex%3B%0A%20%20%20%20%20%20%20%20if(level%20%3C
%2015)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20level%20%2B%3D
%201%0A%20%20%20%20%20%20%20%20%20%20%20%20setTimeout
(stepExpressionToRun%2C%20100)%3B%0A%20%20%20%20%20%20%20%20%7D%0A
%20%20%20%20%7D%3B%0A%20%20%20%20setTimeout(stepExpressionToRun%2C
%20100)%3B%0A%7D%3B%0Afade(document.body)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar
%20add_the_handlers%20%3D%20function(nodes)%20%7B%0A%20%20%20%20var
%20index%3B%0A%20%20%20%20for(index%20%3D%200%3B%20index%20%3C
%20nodes.length%3B%20index%20%2B%3D%201)%20%7B%0A
%20%20%20%20%20%20%20%20nodes%5Bindex%5D.onclick%20%3D%20function
(index)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20function
(anExpression)%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert(anExpression)%3B
%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A
%20%20%20%20%20%20%20%20%7D(index)%3B%0A%20%20%20%20%7D%0A%7D%3B
%0Aadd_the_handlers(document)%3B%0A%0Adocument.writeln(%22%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0Adocument.writeln(%22%2F%2F
%20Chapter%204%20-%20Functions%20-%20Module%22)%3B%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%2F%2F%20My
%20additions%20start%0AString.prototype.startsWith%20%3D%20function
(str)%0A%7B%0A%20%20%20%20return%20(this.match(%22%5E%22%2Bstr)%3D
%3Dstr)%0A%20%20%20%20%7D%0AString.prototype.endsWith%20%3D%20function
(str)%0A%7B%0A%20%20%20%20return%20(this.match(str%2B%22%24%22)%3D
%3Dstr)%0A%20%20%20%20%7D%0A%2F%2F%20My%20additions%20end%0A%0A%2F%2F
%20-------------------------------------------------%0AString.method
('deEntityify'%2C%0A%20%20%20%20function()%20%7B%0A
%20%20%20%20%20%20%20%20var%20entityNamesToCharacterMapTable%20%3D
%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20quot%3A%20'%22'%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20lt%3A%20'%3C'%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20gt%3A%20'%3E'%0A
%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20return
%20function()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return
%20this.replace(%2F%26(%5B%5E%26%3B%5D%2B)%3B%2Fg%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20function
(originalStringBeingReplaced%2C%20tokenToReplaceKey)%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var
%20replacementValueFromTable%20%3D%20entityNamesToCharacterMapTable
%5BtokenToReplaceKey%5D%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var
%20theNewChar%20%3D%20originalStringBeingReplaced.startsWith
(%22%26%22)%3F(%22Starts%20With%20%26%22%2BoriginalStringBeingReplaced)
%3AoriginalStringBeingReplaced%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20document.writeln
(%22originalStringBeingReplaced%3D%20%22%2BtheNewChar%2B%22%2C
%20tokenToReplaceKey%3D%20%22%2BtokenToReplaceKey%2B%22%2C
%20replacementValueFromTable%3D%20%22%2BreplacementValueFromTable)%3B
%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return
%20(typeof%20replacementValueFromTable%20%3D%3D%3D%20'string')%20%3F
%20replacementValueFromTable%20%3A%20originalStringBeingReplaced%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%3B%0A
%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%7D()%0A%20%20%20%20)%3B
%0Avar%20deEntityificationResult%20%3D%20'%26lt%3B%26quot%3B%26gt
%3B'.deEntityify()%3B%0Adocument.writeln(%22'%26amp%3Blt%3B%26amp
%3Bquot%3B%26amp%3Bgt%3B'.deEntityify()%3D
%20%22%2BdeEntityificationResult)%3B%0A%0A%2F%2F
%20-------------------------------------------------%0Avar
%20serial_maker%20%3D%20function()%20%7B%0A%20%20%20%20var%20prefix
%20%3D%20''%3B%0A%20%20%20%20var%20sequence%20%3D%200%3B%0A
%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20set_prefix%20%3A
%20function(aPrefix)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20prefix
%20%3D%20String(aPrefix)%3B%0A%20%20%20%20%20%20%20%20%7D%2C%0A
%20%20%20%20%20%20%20%20set_sequence%20%3A%20function(aSequence)%20%7B
%0A%20%20%20%20%20%20%20%20%20%20%20%20sequence%20%3D%20aSequence%3B%0A
%20%20%20%20%20%20%20%20%7D%2C%0A
%20%20%20%20%20%20%20%20generateSerialNumber%20%3A%20function()%20%7B
%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20result%20%3D%20prefix
%20%2B%20sequence%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20sequence
%20%2B%3D%201%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20document.writeln
(%22prefix%3D%20%22%2Bprefix%2B%22%2C%20After%20incrementing%2C
%20sequence%3D%20%22%2Bsequence)%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20return%20result%3B%0A
%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3B%0A%7D%3B%0Avar
%20sequencer%20%3D%20serial_maker()%3B%0Asequencer.set_prefix(%22Q
%22)%3B%0Asequencer.set_sequence(1000)%3B%0Avar%20unique%20%3D
%20sequencer.generateSerialNumber()%3B%0Adocument.writeln
(%22sequencer.generateSerialNumber()%3D%20%22%2Bunique)%3B%0A%2F%2F
%20-------------------------------------------------%0A%0A%2F
%2Fdocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0A%2F%2Fdocument.writeln(%22%2F%2F%20Chapter%204%20-
%20Functions%20-%20Cascade%22)%3B%0A%2F%2Fdocument.writeln(%22%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2FgetElement
('myBoxDiv').%0A%2F%2F%20%20%20%20move(350%2C%20150).%0A%2F%2F
%20%20%20%20width(100).%0A%2F%2F%20%20%20%20height(100).%0A%2F%2F
%20%20%20%20color('red').%0A%2F%2F%20%20%20%20border('10px%20outset').
%0A%2F%2F%20%20%20%20padding('4px').%0A%2F%2F%20%20%20%20appendText
(%22Please%20stand%20by%22).%0A%2F%2F%20%20%20%20on(%0A%2F%2F
%20%20%20%20%20%20%20%20'mousedown'%2C%0A%2F%2F
%20%20%20%20%20%20%20%20function(m)%20%7B%0A%2F%2F
%20%20%20%20%20%20%20%20%20%20%20%20this.startDrag(m%2C%20this.getNinth
(m))%3B%0A%2F%2F%20%20%20%20%20%20%20%20%7D%0A%2F%2F
%20%20%20%20%20%20%20%20).%0A%2F%2F%20%20%20%20on('mousemove'%2C
%20'drag').%0A%2F%2F%20%20%20%20on('mouseup'%2C%20'stopDrag').%0A%2F%2F
%20%20%20%20later(%0A%2F%2F%20%20%20%20%20%20%20%202000%2C%0A%2F%2F
%20%20%20%20%20%20%20%20function()%20%7B%0A%2F%2F
%20%20%20%20%20%20%20%20%20%20%20%20this.color('yellow').%0A%2F%2F
%20%20%20%20%20%20%20%20%20%20%20%20setHTML(%22What%20hath%20God
%20wrought%3F%22).%0A%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20slide
(400%2C%2040%2C%20200%2C200)%3B%0A%2F%2F%20%20%20%20%20%20%20%20%7D%0A
%2F%2F%20%20%20%20%20%20%20%20).%0A%2F%2F%20%20%20%20tip('This%20box
%20is%20resizable')%3B%0A%2F%2F
%20-------------------------------------------------%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20Curry%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0AFunction.method
('curry'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20function
()%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20slice
%20%3D%20Array.prototype.slice%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20args
%20%3D%20slice.apply(arguments)%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20that
%20%3D%20this%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return
%20function()%20%7B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return
%20that.apply(null%2C%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20args.concat
(slice.apply(arguments)))%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A)%3B%0Avar
%20add1%20%3D%20add.curry(1)%3B%0Adocument.writeln(%22add1(6)%3D
%20%22%2Badd1(6))%3B%0A%2F%2F
%20-------------------------------------------------%0A%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B
%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0A%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B
%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0A%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0Adocument.writeln
(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%22)%3B
%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------%0A%0A%0A
%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%22)%3B%0Adocument.writeln(%22%2F%2F%20Chapter%204%20-%20Functions%20-
%20%22)%3B%0Adocument.writeln(%22%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F
%2F%2F%2F%22)%3B%0A%2F%2F
%20-------------------------------------------------%0A%2F%2F
%20-------------------------------------------------

Nick Santos

unread,
Nov 5, 2009, 2:15:40 PM11/5/09
to closure-comp...@googlegroups.com
Hi Gopalan,

Posting to this group is a good way to report problems. :)

Would it be possible for you to post the original code as well?

Thanks,
Nick

Gopalan Raj

unread,
Nov 5, 2009, 2:21:07 PM11/5/09
to closure-comp...@googlegroups.com
Here goes the test code:

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
document.writeln("Hello, Gopalan Suresh Raj");

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Object Literals");
document.writeln("//////////////////////////////////////");
var empty_object = {};
var stooge = {
    "first-name":"Gopalan",
    "middle-name":"Suresh",
    "last-name":"Raj"
};
document.writeln("stooge[\"FIRST-NAME\"]= "+stooge["FIRST-NAME"]);
document.writeln("stooge[\"middle-name\"]= "+stooge["middle-name"]);

var flight = {
    airline: "Oceanic",
    number: 815,
    departure: {
        IATA: "MAS",
        time: "2009-09-22 14:55",
        city: "Chennai"
    },
    arrival: {
        IATA: "LAX",
        time: "2009-09-23 10:42",
        city: "Los Angeles"
    }
};

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Retrieval");
document.writeln("//////////////////////////////////////");
document.writeln("flight.status= "+flight.status);

var nickname = stooge["nick-name"] || "(none)";
document.writeln("nickname= "+nickname);
var status = flight.status || "unknown";
document.writeln("status= "+status);

var theEquipment = flight.equipment;
document.writeln("flight.equipment= "+flight.equipment);

//var theModel = flight.equipment.model;
//document.writeln(theModel);
//
//var theCombo = flight.equipment && flight.equipment.model;
//document.writeln(theCombo);

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Update");
document.writeln("//////////////////////////////////////");
stooge["other-name"] = "Suresh Raj Gopalan";
document.writeln("stooge[\"other-name\"]= "+stooge["other-name"]);
stooge.nickname = "Suresh";
document.writeln("stooge.nickname= "+stooge.nickname);
flight.equipment = {
    model : 'Boeing 777'
};
document.writeln("flight.equipment.model= "+flight.equipment.model);
flight.status = 'overdue';
document.writeln("flight.status= "+flight.status);

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Reference");
document.writeln("//////////////////////////////////////");
var x = stooge;
document.writeln("x= "+x);
x.nickname = "The Raj";
document.writeln("x.nickname= "+x.nickname);
var nick = stooge.nickname;
document.writeln("nick= "+nick);

var a = {
    value:"a"
}, b = {
    value:"b"
}, c = {
    value:"c"
};
document.writeln("a.value= "+a.value);
document.writeln("b.value= "+b.value);
document.writeln("c.value= "+c.value);

a = b = c = {
    value:"common d"
};
document.writeln("a.value= "+a.value);
document.writeln("b.value= "+b.value);
document.writeln("c.value= "+c.value);

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Prototype");
document.writeln("//////////////////////////////////////");
if(typeof Object.create !== 'function') {
    Object.create = function(anObject) {
        var aFunctionVariable = function() {};
        aFunctionVariable.prototype = anObject;
        return new aFunctionVariable();
    };
}
var another_stooge = Object.create(stooge);
another_stooge['first-name'] = 'Suresh';
document.writeln("another_stooge['first-name']= "+another_stooge['first-name']);
another_stooge['middle-name'] = 'Raj';
document.writeln("another_stooge['middle-name']= "+another_stooge['middle-name']);
another_stooge.nickname = 'Raj';
document.writeln("another_stooge.nickname= "+another_stooge.nickname);

stooge.profession = 'actor';
document.writeln("stooge.profession= "+stooge.profession);
document.writeln("another_stooge.profession= "+another_stooge.profession);

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Reflection");
document.writeln("//////////////////////////////////////");

document.writeln("typeof flight.number= "+typeof flight.number);
document.writeln("typeof flight.status= "+typeof flight.status);
document.writeln("typeof flight.arrival= "+typeof flight.arrival);
document.writeln("typeof flight.manifest= "+typeof flight.manifest);

document.writeln("typeof flight.toString= "+typeof flight.toString);
document.writeln("typeof flight.constructor= "+typeof flight.constructor);

document.writeln("flight.hasOwnProperty('number')= "+flight.hasOwnProperty('number'));
document.writeln("flight.hasOwnProperty('constructor')= "+flight.hasOwnProperty('constructor'));


document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Enumeration");
document.writeln("//////////////////////////////////////");

var attribute;
for(attribute in another_stooge) {
    if(typeof another_stooge[attribute] !== 'function') {
        document.writeln(attribute+':'+another_stooge[attribute]);
    }
}

var index;
var properties = [
'first-name',
'middle-name',
'last-name',
'profession'
];
for(index = 0; index < properties.length; index += 1) {
    document.writeln(properties[index] + ":" + another_stooge[properties[index]]);
}

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Delete");
document.writeln("//////////////////////////////////////");

document.writeln("another_stooge.nickname= "+another_stooge.nickname);
delete another_stooge.nickname;
document.writeln("another_stooge.nickname= "+another_stooge.nickname);


document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 3 - Objects - Global Abatement");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var MYAPP = {};

MYAPP.stooge = {
    "first-name" : "Gopalan",
    "middle-name" : "Suresh",
    "last-name" : "Raj"
};

document.writeln("MYAPP.stooge[\"first-name\"]= "+MYAPP.stooge["first-name"]);
document.writeln("MYAPP.stooge[\"middle-name\"]= "+MYAPP.stooge["middle-name"]);
document.writeln("MYAPP.stooge[\"last-name\"]= "+MYAPP.stooge["last-name"]);

MYAPP.flight = {
    airline : "Oceanic",
    number : 815,
    departure : {
        IATA : "MAA",
        time : "2009-09-22 14:55",
        city : "Chennai"
    },
    arrival : {
        IATA : "LAX",
        time : "2009-09-23 10:42",
        city : "Los Angeles"
    }
};
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Function Literal");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var add = function(a, b) {
    return a + b;
};
var total = add(7,3);
document.writeln("add(7,3)= "+total);
// -------------------------------------------------


document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Method Invocation Pattern");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var myObject = {
    value : 0,
    increment : function(anIncrement) {
        this.value += (typeof anIncrement === 'number') ? anIncrement : 1;
    }
};
myObject.increment();
document.writeln("myObject.increment()= "+myObject.value+" is the value of myObject.value");

myObject.increment(2);
document.writeln("myObject.increment(2)= "+myObject.value+" is the value of myObject.value");
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Function Invocation Pattern");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var sum = add(9,1);
document.writeln("add(9,1)= "+sum);

// -------------------------------------------------
myObject.myDouble = function() {
    var that = this; // workaround
    var helper = function() {
        that.value = add(that.value, that.value);
    };
    helper(); // Invoke helper as a function
};
myObject.myDouble();
document.writeln("myObject.myDouble()= "+myObject.value+" is the value of myObject.value");
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Constructor Invocation Pattern ");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var Quote = function(aString) {
    this.status = aString;
};
Quote.prototype.get_status = function() {
    return this.status;
}
var myQuote = new Quote("confused!!!");
document.writeln("myQuote.get_status()= "+myQuote.get_status());
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Apply Invocation Pattern");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var array = [6,4];
var aSum = add.apply(null, array);
document.writeln("add.apply(null, array)= "+aSum);

// -------------------------------------------------
var statusObject = {
    status : 'A-OK'
};
var aStatus = Quote.prototype.get_status.apply(statusObject);
document.writeln("Quote.prototype.get_status.apply(statusObject)= "+aStatus);
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Arguments");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var arraySum = function() {
    var index, theArraySum = 0;
    for(index = 0; index < arguments.length; index += 1) {
        theArraySum += arguments[index];
    }
    return theArraySum;
};
document.writeln("arraySum(4,8,12,16,20,24,28)= "+arraySum(4,8,12,16,20,24,28));
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var safeAdd = function(a, b) {
    if(typeof a !== 'number' || typeof b !== 'number') {
        throw {
            name : 'TypeError',
            message : 'safeAdd needs numbers'
        };
    }
    return a + b;
};

// -------------------------------------------------
var trySafeAdd = function() {
    try {
        safeAdd("seven");
    } catch(exception) {
        document.writeln("Exception from trySafeAdd");
        document.writeln(exception.name + ' : ' + exception.message);
    }
};
trySafeAdd();
// -------------------------------------------------


document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Augmenting Types");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
Function.prototype.method = function(name, aFunction) {
    if(!this.prototype[name]) {
        this.prototype[name] = aFunction;
    }
    return this;
};
Number.method('integer',
    function() {
        return Math[(this < 0)?'ceil':'floor'](this);
    }
    );
document.writeln("(-10/3).integer()= "+(-10/3).integer());

// -------------------------------------------------
String.method('trim',
    function() {
        var regularExpression = /^\s+|\s+$/g;
        return this.replace(regularExpression, '');
    }
    );
document.writeln('"'+ "      neat!    ".trim()+'"');
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Recursion");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var hanoi = function hanoi(disc, source, auxillary, destination) {
    if(disc > 0) {
        hanoi(disc-1, source, destination, auxillary);
        document.writeln('Move disc# '+disc+' from '+source+' to '+ destination);
        hanoi(disc-1, auxillary, source, destination);
    }
};
hanoi(3, 'Source', 'Auxillary', 'Destination');

// -------------------------------------------------
var walk_the_DOM = function walk(node, aFunction) {
    aFunction(node);
    node = node.firstChild;
    while(node) {
        walk(node, aFunction);
        node = node.nextSibling;
    }
};
var getElementsByAttribute = function(anAttribute, value) {
    var results = [];
    walk_the_DOM(document.body,
        function(node) {
            var actual = node.nodeType === 1 && node.getAttribute(anAttribute);
            if( (typeof actual === 'string') &&
                ((actual === value) || (typeof value !== 'string')) ) {
                results.push(node);
            }
        }
        );
    return results;
};
var theAttributes = getElementsByAttribute('src');
for(value in theAttributes) {
    document.writeln(value);
}

// -------------------------------------------------
var factorial = function factorial(theNumber, index) {
    index = index || 1;
    if(theNumber < 2) {
        return index;
    }
    return factorial(theNumber-1, theNumber*index);
};
document.writeln("factorial(10)= "+factorial(10));
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Scope");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var fooFunction = function() {
    var a = 3, b = 5;
    document.writeln("Inside fooFunction (after a = 3, b = 5), a = "+a+", b = "+b);
    var barFunction = function() {
        var b = 7, e = 11;
        document.writeln("Inside barFunction (after b = 7, c = 11), a = "+a+", b = "+b+", e = "+e);
        a += b + e;
        document.writeln("Inside barFunction (after a += b + c), a = "+a+", b = "+b+", e = "+e);
    };
    document.writeln("Inside fooFunction (after a = 3, b = 5), a = "+a+", b = "+b);
    barFunction();
    document.writeln("Inside fooFunction (after invoking barFunction(), a = "+a+", b = "+b);
};
fooFunction();
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Closure");
document.writeln("//////////////////////////////////////");

// -------------------------------------------------
var someObject = function() {
    var value = 0;
    return {
        increment: function(anIncrement)  {
            value += (typeof anIncrement === 'number')?anIncrement : 1;
        },
        getValue: function() {
            return value;
        }
    };
}();
someObject.increment(9);
someObject.increment(1);
document.writeln("someObject.increment(9)= "+someObject.getValue()+" is the value of someObject.getValue()");

// -------------------------------------------------
var someQuote = function(status) {
    return {
        get_status: function() {
            return status;
        }
    };
};
var mySomeQuote = someQuote('amazed!');
document.writeln("someQuote('amazed!')= "+mySomeQuote.get_status()+" is the value of mySomeQuote.get_status()");


// -------------------------------------------------
var fade = function(node) {
    var level = 1;
    var stepExpressionToRun = function() {
        var hex = level.toString(16);
        node.style.backgroundColor = '#FFFF'+hex+hex;
        if(level < 15) {
            level += 1
            setTimeout(stepExpressionToRun, 100);
        }
    };
    setTimeout(stepExpressionToRun, 100);
};
fade(document.body);

// -------------------------------------------------
var add_the_handlers = function(nodes) {
    var index;
    for(index = 0; index < nodes.length; index += 1) {
        nodes[index].onclick = function(index) {
            return function(anExpression) {
                alert(anExpression);
            };
        }(index);
    }
};
add_the_handlers(document);

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Module");
document.writeln("//////////////////////////////////////");
// My additions start
String.prototype.startsWith = function(str)
{
    return (this.match("^"+str)==str)
    }
String.prototype.endsWith = function(str)
{
    return (this.match(str+"$")==str)
    }
// My additions end

// -------------------------------------------------
String.method('deEntityify',
    function() {
        var entityNamesToCharacterMapTable = {
            quot: '"',
            lt: '<',
            gt: '>'
        };
        return function() {
            return this.replace(/&([^&;]+);/g,
                function(originalStringBeingReplaced, tokenToReplaceKey) {
                    var replacementValueFromTable = entityNamesToCharacterMapTable[tokenToReplaceKey];
                    var theNewChar = originalStringBeingReplaced.startsWith("&")?("Starts With &"+originalStringBeingReplaced):originalStringBeingReplaced;
                    document.writeln("originalStringBeingReplaced= "+theNewChar+", tokenToReplaceKey= "+tokenToReplaceKey+", replacementValueFromTable= "+replacementValueFromTable);
                    return (typeof replacementValueFromTable === 'string') ? replacementValueFromTable : originalStringBeingReplaced;
                }
                );
        };
    }()
    );
var deEntityificationResult = '&lt;&quot;&gt;'.deEntityify();
document.writeln("'&amp;lt;&amp;quot;&amp;gt;'.deEntityify()= "+deEntityificationResult);

// -------------------------------------------------
var serial_maker = function() {
    var prefix = '';
    var sequence = 0;
    return {
        set_prefix : function(aPrefix) {
            prefix = String(aPrefix);
        },
        set_sequence : function(aSequence) {
            sequence = aSequence;
        },
        generateSerialNumber : function() {
            var result = prefix + sequence;
            sequence += 1;
            document.writeln("prefix= "+prefix+", After incrementing, sequence= "+sequence);
            return result;
        }
    };
};
var sequencer = serial_maker();
sequencer.set_prefix("Q");
sequencer.set_sequence(1000);
var unique = sequencer.generateSerialNumber();
document.writeln("sequencer.generateSerialNumber()= "+unique);
// -------------------------------------------------

//document.writeln("//////////////////////////////////////");
//document.writeln("// Chapter 4 - Functions - Cascade");
//document.writeln("//////////////////////////////////////");
// -------------------------------------------------
//getElement('myBoxDiv').
//    move(350, 150).
//    width(100).
//    height(100).
//    color('red').
//    border('10px outset').
//    padding('4px').
//    appendText("Please stand by").
//    on(
//        'mousedown',
//        function(m) {
//            this.startDrag(m, this.getNinth(m));
//        }
//        ).
//    on('mousemove', 'drag').
//    on('mouseup', 'stopDrag').
//    later(
//        2000,
//        function() {
//            this.color('yellow').
//            setHTML("What hath God wrought?").
//            slide(400, 40, 200,200);
//        }
//        ).
//    tip('This box is resizable');
// -------------------------------------------------

document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - Curry");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
Function.method('curry',
                function() {
                    var slice = Array.prototype.slice,
                        args = slice.apply(arguments),
                        that = this;
                    return function() {
                        return that.apply(null,
                                          args.concat(slice.apply(arguments)))
                    };
                }
);
var add1 = add.curry(1);
document.writeln("add1(6)= "+add1(6));
// -------------------------------------------------



document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------
document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------



document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------
document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------



document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------
document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------



document.writeln("//////////////////////////////////////");
document.writeln("// Chapter 4 - Functions - ");
document.writeln("//////////////////////////////////////");
// -------------------------------------------------
// -------------------------------------------------
--
Co-Author of:
1. Professional JMS Programming (Wrox Press)
2. Enterprise Java Computing : Applications and Architecture (Cambridge University Press)
3. The Awesome Power of JavaBeans (Manning Publications)

________________________________________________
Copyright (c) 2009, Gopalan Suresh Raj. All Rights Reserved.

You can view my Blog at http://blogs.sun.com/gopalan

Public Profile at: http://www.google.com/profiles/ipersist

Visit me at Web Cornucopia at http://my.execpc.com/~gopalan/
Web Cornucopia - The Ultimate Resource for developing Distributed, multi-tier, Enterprise Solutions using COM+/Windows DNA, Java/J2EE, CCM/CORBA 3.0, The Microsoft .NET Framework, and all their related technologies.

Nick Santos

unread,
Nov 5, 2009, 3:11:43 PM11/5/09
to closure-comp...@googlegroups.com
Thanks for the bug report! I filed it as
http://code.google.com/p/closure-compiler/issues/detail?id=1

I think I've got a fix that will get pushed out in the next couple of
days. In the meantime, you can workaround it by renaming walk ->
walk_the_DOM

Nick

Nick Santos

unread,
Nov 7, 2009, 2:40:49 PM11/7/09
to closure-comp...@googlegroups.com
OK, this should be fixed now.
Reply all
Reply to author
Forward
0 new messages