首页> 美国政府科技报告 >Server-Side JavaScript Debugging: Viewing the Contents of an Object; ViewSource Online Magazine
【24h】

Server-Side JavaScript Debugging: Viewing the Contents of an Object; ViewSource Online Magazine

机译:服务器端Javascript调试:查看对象的内容; Viewsource在线杂志

获取原文

摘要

JavaScript allows the definition and use of large, complex objects. Unlike some other object-oriented languages, it also allows run-time modifications not only of the values of object components, but also of the very structure of the object itself. This feature is powerfnl and sometimes very convenient, but it can be difficult to keep track of the object's structure and values throughout program execution. What's needed is a simple way to view the current state of an object at any point during execution. There is a debug function that is included in the Netscape server-side JavaScript environment. The fiction outputs the value(s) of the expression given as the argument to the function in the JavaScript Application Manager's debug window (SSJS). For example, the following lines in Figure 1 of a server:side JavaScript program Debug message: x.myVal = 1 Debug message: x.myArr(O) = 2 Debug message: x.myStr = test Debug message: x.myFunc = function myFunc (argl, arg2 ) ( return (argl - arg2 );) Debug message: sum = 4 Debug message: x = (object Object) This fhnction is useful for checking the values of individual variables or expressions. But it doesn't tell you much about more complex data structures, such as the object variable 'x' in the example. It would be more useful to see the values of all elements in an array or properties in an object. (For purposes of this discussion, an array can be considered a type of object. When the word 'object' appears below, interpret that to include arrays also.) To aid us in viewing object structure in our programs, we have written a recursive function called dump which steps through all the properties in an object, outputting a type, name, and value for each. Using the same example object above, a fhnction call such as the one in Figure 3: Debug message: number: x.myVal = 1 Debug message: number: x.myArr. O = 2 Debug message: number: x.myArr.l = 3 Debug message: String: x.myStr = test Debug message: function: x.myFunc = myFunc(argl, arg2).

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号