AnsweredAssumed Answered

Override function with prototype

Question asked by wanderer2019 on Feb 17, 2010

i need to write a function similar to .NET String.Format in JavaScript.

So, i use this:
String.format = String.prototype.format= function() {
      var string = this;
      var i=0;

      if (typeof(this) == "function") {
         string = arguments[0];

      for (; i < arguments.length; i++)
         string = string.replace(/\{\d+?\}/, arguments[i]);

      return string;

but when ever i call it from alfresco side web-script i get exception:
Caused by: org.mozilla.javascript.EvaluatorException: Cannot modify a property of a sealed object: format.

But in standalone html page (out of alfresco) script works fine.

Any suggestions? what should i change?