javascript - CrossRider - is there a way to pass arrays as function parameters without converting them to objects? -


we using crossrider develop extension internet explorer. have object downloaded http://jsons.[part_of_link_suppressed].com.s3.amazonaws.com/selectors.json. found out when object sent callback, arrays converted objects integer keys. why arrays converted objects , there way prevent it? know can json.stringify object , json.parse calling function, there way send arrays without converting them strings? checked , ['a','b','c'] converted object ({"0":"a","1":"b","2":"c"}) when calling function it.

i'm using internet explorer 11 extension should work on versions of internet explorer.

edit (1): tested debug mode in internet explorer 11 , google chrome. created new extension - id 67708. in chrome works fine, in explorer doesn't. here code:

background.js:

/************************************************************************************   background code.   more information please visit our wiki site:   http://docs.crossrider.com/#!/guide/scopes_background *************************************************************************************/  function callme1() {     var r1 = ['a','b','c'];     alert('r1 = ' + json.stringify(r1));     return r1; }  appapi.ready(function($) {    // place code here (ideal handling browser button, global timers, etc.)   alert('callme1() = ' + json.stringify(callme1()));  }); 

extension.js:

  /************************************************************************************   page code. appapi.ready() code block executed on every page load.   more information please visit our docs site: http://docs.crossrider.com *************************************************************************************/  function callme2() {     var r2 = ['a','b','c'];     alert('r2 = ' + json.stringify(r2));     return r2; }  appapi.ready(function($) {      // place code here (you can define new functions above scope)     // $ object extension's jquery object      // alert("my new crossrider extension works! current page is: " + document.location.href);     alert('callme2() = ' + json.stringify(callme2()));  }); 

in chrome alerts ["a","b","c"], in explorer {"0":"a","1":"b","2":"c"}, before , after returning object. in our extension (id 43889), if json.stringify object , json.parse it, it's still array (i didn't find how reproduce simple extension).

by way, if type in console json.stringify(['a','b','c']) in explorer or chrome, same result - "["a","b","c"]".

i found irritating bug - crossrider converts staging extensions production, , have switch again staging manually. happened @ least 5 times both extensions.

edit (2): tried use appapi.json.stringify instead of json.stringify , receive correct results in explorer in extension.js (["a","b","c"]), background.js not loaded @ in debug mode , keeps displaying old contents. don't know if that's because have 2 extensions in debug mode new bug - background.js not updated when click "reload background code".

i had same problem, messaging api. not sure case (when saving db?)

though don't remember whole debugging findings think that: crossrider api internally serialising values json in order send them via postmessage/their own implementation background communication background ie process(for browser/not natively support pass objects via postmessage eg ie8). aren't using native json object rather (broken) json implementation (i think on ie background process because not browser page , there's no built in json) means if use appapi.json when no native json available still broken arrays.

my solution use external json library, think used json3 http://bestiejs.github.io/json3/ http://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js less performant if not big object won't noticeable.

you can try monkey patch json appapi.json external library, might fix api


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -