JScript prend-il en charge la méthode de suppression de chaînes?

Lors du développement d’une procédure Windows utilisant JScript, il semble que certaines méthodes de chaînes ne fonctionnent pas. Dans cet exemple utilisant sortingm, la ligne 3 génère l’erreur d’exécution:

“L’object ne supporte pas cette propriété ou méthode”.

Mon code:

strParent = " a "; strParent = strParent.sortingm(); WScript.Echo ("Value: " + strParent); 

Est-ce que je suis stupide? Des idées quel est le problème?

Vous pouvez append sortingm à la classe Ssortingng:

sortingm-test.js

 Ssortingng.prototype.sortingm = function() { return this.replace(/^\s+|\s+$/g, ''); }; strParent = " a "; strParent = strParent.sortingm(); WScript.Echo ("Value: " + strParent); 

Sortie de cmd.exe

 C:\>cscript //nologo sortingm-test.js Value: a 

JScript s’exécutant sous Windows Scripting Host utilise une ancienne version de JScript basée sur ECMAScript 3.0. La fonction sortingm a été introduite dans ECMAScript 5.0.

Utilisez un polyfill, par exemple celui-ci: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ssortingng/Trim#Polyfill

Cet extrait:

 if (!Ssortingng.prototype.sortingm) { Ssortingng.prototype.sortingm = function () { return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }; } strParent = " a "; strParent = strParent.sortingm(); WScript.Echo ("Value: '" + strParent + "'"); 

va sortir

 Value: 'a'