Menu

ECMA Compatibility

devnull
2024-01-17
2024-01-22
  • devnull

    devnull - 2024-01-17

    I ran into trouble using some, i thought standard ECMA-262 Javascript methods, which i need to "rebuild".

    No support for .format() using placeholders (sprintf-style).
    Added with extending the object:

    if (!String.prototype.format) {
      String.prototype.format = function() {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, number) { 
          return typeof args[number] != 'undefined'
            ? args[number]
            : match
          ;
        });
      };
    }
    

    No support for .keys() method on arrays

    if (!Object.keys) {
        Object.keys = function (object) {
            var keys = [];
    
            for (var key in object) {
                if (object.hasOwnProperty(key)) {
                    keys.push(key);
                }
            }
        }
    }
    
     
  • Stefan Zieker

    Stefan Zieker - 2024-01-18

    ScriptCommunicator uses the the Qt class QJSEngine to execute the scripts. If this class does not support these functions, I can't do anything about it.

     
  • Stefan Zieker

    Stefan Zieker - 2024-01-18

    I think String.prototye.format and String.prototype.keys are not standard JavaScript. Look here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

     

    Last edit: Stefan Zieker 2024-01-18
  • devnull

    devnull - 2024-01-20

    Also strange, regarding the docs your linked it should know replaceAll() but if i use this method, the script internally aborts/stops without giving any error (at least i see none). I had to use replace(REGEX/g, "..") instead.

     

    Last edit: devnull 2024-01-20
  • Stefan Zieker

    Stefan Zieker - 2024-01-22

    I will look into when I have time. Thx for reporting this.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.