fisherman1
New Member
I was working with a javascript API and I saw this quote: \[quote\] Because JavaScript is a scripting language, every line of code takes up valuable processor time. One way to improve processor time is to chain method calls to reduce lines of code. Objects such as esri.Graphic and esri.symbol.* provide setter methods that return the object itself, allowing for chaining of methods. Less efficient:\[/quote\]\[code\]var symbol = new esri.symbol.SimpleMarkerSymbol();symbol.setSize(10);symbol.setColor(new dojo.Color([255,0,0]));\[/code\]\[quote\] More efficient:\[/quote\]\[code\]var symbol = new esri.symbol.SimpleMarkerSymbol().setSize(10).setColor(new dojo.Color([255,0,0]));\[/code\]\[quote\] When chaining method calls, you need to determine a balance between efficiency and readability of your code. Your code might be more readable and maintainable if you avoid chaining; however, you will forfeit the performance benefit that chaining offers.\[/quote\]I understand in Java, writing a chain method vs the stack of methods should compile down to the same bytecode. However, since this is a scripting language, does this really hold water? Also, if it does, is it worth sacrificing the readability for the code for the performance of that section of code?And for reference on where I got this text from: http://help.arcgis.com/en/webapi/javascript/arcgis/jshelp/inside_graphics.html