0 votes

Hi,

in the serverscripts contexts (like a taskscheduler) I try to use some function that are not implemented (eg : Array.prototype.splice, or indexof) by the efficy js compiler (? am I right?).

anyway, i used in my script a typical prototype's override like :

Array.prototype.splice = function (_index, _length, _elems){
    var result = new Array();
    var i = 0;

    while (i < _index){
        result.push(this[i]);
        i++;
    }

    if (_elems) for (var j=0; j<_elems.length; j++) result.push(_elems[j]);

    i = _index + _length;

    while (i<this.length){
        result.push(this[i]);
        i++;
    }

    this = result;
};

At this point I don't even care about my code working or not, being optimized or not...

Then in my code I try to call my prototype by using a classic :

myArray.splice(1, 2);

but efficy throw me an error like my method doesn't exist...

I can only assume that the prototype I override is not the one called by my code after the Efficy dual language compiler has done its work.

Am I right in my interpretation?
what would you recommand me to use to make those kind of overrides?
is it forecast to implement a real JS engine to Efficy? (please tell me you will convert efficy dll as a nodejs application)

meanwhile if you need to use those kind of functionnalities this is what I ve temporarly done :

function splice(_array, _index, _length, _elems){
    var result = new Array();
    var i = 0;

    while (i < _index){
        result.push(_array[i]);
        i++;
    }

    if (_elems) for (var j=0; j<_elems.length; j++) result.push(_elems[j]);

    i = _index + _length;

    while (i<_array.length){
        result.push(_array[i]);
        i++;
    }

    return result;
};

and then I call it this way :

myTab = splice(myTab, 1, 2);
asked in Efficy/ Client side by (989 points)

2 Answers

+1 vote
Best answer

Hello Louis,

  • Efficy will not be converted to nodejs ;)
  • Efficy uses a "real JS engine", the one implemented in WSH, JScript
  • The reason these functions are "missing" is that the version of JScript used by efficy is a legacy one for technical reasons
  • Efficy 11 has numerous improvements with serverside JS, one of them having upgraded the support to a newer version of JScript which has these methods, as well as JSON support.
  • Prototype overrides have worked since forever, there is the following example in Places_server.js : String.prototype.format = function() { ... });

Stay tuned ;)

answered by (449 points)
selected by
too bad for node^^ thank you for your reply.
Louis, you have also other examples of polyfills in serverscripts/CommonLibrary (end of the file) ;)
0 votes

there a working polyfill. my code was just lame...

Array.prototype.splice = function(){
    var args = arguments;

    var result = new Array();
    var i = 0;

    while (i < args[0]){
        result.push(this[i]);
        i++;
    }

    if (args[2])    for (var j=0; j<args[2].length; j++) result.push(args[2][j]);

    i = args[0] + args[1];

    while (i<this.length){
        result.push(this[i]);
        i++;
    }

    for (i=0; i<this.length; i++) this[i] = undefined;
    this.length = 0;
    for (i=0; i<result.length; i++) this.push(result[i]);

    return this;
}

Warning this code has not been tested properly. but the override is effective.
call exemple :

myArr = ["Alexandre", "has", "the", "best", "answer"];       // Alexandre, has, the, best, answer
myArr.splice(1, 1, ["is"]).splice(4, 1);                     // Alexandre, is, the, best
answered by (989 points)
hahahah Louis ! well played ;)
1,248 questions
1,518 answers
1,858 comments
328 users