开发者

XSLT+JavaScript: using classes

I'm trying to use classes in XSL (the 'msxsl:script' tag). But I get the 'Syntax error' message when debugging the file. Here's a simple code that I'm using:

function Test1(str)
{
    this.str = str;
}

Test1.prototype.getStr = function()
{
    return this.str;
}

function t开发者_JAVA百科est()
{
    var newTest1 = new Test1("some string");
    return (newTest1.getStr());
}

If I insert the code to a aspx file and call the test function, everything works fine, without any error messages. Is it possible to use classes in XSL?


It seems that there are some odd restrictions on what you can use at the top level of the script blocks, and that they won't allow the use of this in top-level functions. However, if you go one level deeper, some of these restrictions go away:

function MakeTest1()
{
   function inner(s)
   {
      this.str = s;
   }

   inner.prototype.getStr = function()
   {
      return this.str;
   }

   return inner;
}
var Test1 = MakeTest1();

function test()
{
    var newTest1 = new Test1("some string");
    return (newTest1.getStr());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜