Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ISC_Core.js changes array object behavior

    Hi,

    We are using smartGWT 3.0 and additional third party javascript library.
    When ISC_Core.js is included in the html file it changes array object behavior.

    Example: the third party js file need to run the following code that should display 3 message boxes with aaa, bbb, ccc
    Code:
    var test1 = "aaa;bbb;ccc";
    var result1 = test1.split(";");
    for(var i in result1){alert(result1[i]);}
    if we include ISC_Core.js in the html file (what is needed for smartgwt) we receive more a lot message boxes: first 3 are with aaa, bbb, ccc and then a lot of message boxes with smartgwt function implementations.

    How can we solve the issue and make the code display only 3 messages?

    In the example code:
    the row - for(var i in result1){alert(result1[i]);} - is called before ISC_Core.js is included and displays 3 messages.

    the row - for(var i in result2){alert(result2[i]);} - is called after ISC_Core.js is included and displays many messages including function implementation.

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <link href="GWT.css" rel="stylesheet" type="text/css">
    <title>xMS</title>
    <script type="text/javascript">
    	var test1 = "aaa;bbb;ccc";
    	var result1 = test1.split(";");
    	for(var i in result1){alert(result1[i]);}
    </script>
    <script>
    	var isomorphicDir = "gwt/sc/";
    </script>
    
    <script src="http://localhost/xmsdebug/gwt/gwt/sc/modules/ISC_Core.js"
    	language="javascript"></script>
    	
    <link
    	href="http://localhost/xmsdebug/gwt/gwt/sc/skins/Enterprise/skin_styles.css"
    	type="text/css" rel="stylesheet">
    
    
    <script type="text/javascript">
    	var test2 = "aaa;bbb;ccc";
    	var result2 = test2.split(";");
    	for(var i in result2){alert(result2[i]);}
    </script>
    
    <link rel="stylesheet"
    	href="http://localhost/xmsdebug/gwt/gwt/gwt/clean/clean.css">
    </head>
    <body>
    </body>
    </html>
    Thanks,
    Olga.

    #2
    Many common JavaScript libraries add functions to Array. Your third party JavaSript library should be adjusted to compensate for this.

    Note that for..in iteration of an array is also many times slower, so this is best practices anyway.

    Comment


      #3
      Hi,
      I know this thread is 2 years old, but I have the same problem. I can apply following code:

      <script type="text/javascript" id="fixAugmentingJSArray">
      (function() {
      var tmpArray = []
      for (var key in tmpArray) {
      Object.defineProperty(tmpArray.getPrototype(), key, { enumerable:false });
      }
      })();
      </script>

      Then an Array properties are not included in for .. in loop. But still this solution is working only for >IE9 (IE8 supports Object.defineProperty only for DOM objects, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).

      I have already post question to third party library forum dhtmlxGantt (http://forum.dhtmlx.com/viewtopic.php?f=15&t=36268). But just for now it is important to know if this change can not break SmartClient Core.

      Thanks in advance!

      Comment


        #4
        So far as we know, that will have no behavior change, and it's something we plan to do once IE8 is less common.

        However, note that for..in iteration is slower than index iteration, and you will still have problems with lots of different libraries, so we wouldn't really recommend relying on it.

        Comment

        Working...
        X