JScript template and classes

Any template questions or comments or suggestions

JScript template and classes

Postby davidtar on Fri Dec 08, 2006 1:56 am

Does the JScript parser support classes?

We are trying to create a template to generate dotNet 'xsd' files.
Neither of has used JScript before but we do write javascript classes and code for our ajax based webappliaction using 'prototype'.
Code syntax and structure based on http://msdn2.microsoft.com/en-us/library/667a3hk6(VS.80).aspx


The following code results in the following:

[Error] Microsoft JScript compilation error (10, 0) 1002: Syntax error
Stack Traceclass Param {


Code: Select all
class Param {
// Private vars.
   private var _dbType : String;
   private var _direction : String;
   private var _name : String;
   private var _precision : Integer;
   private var _providerType : String;
   private var _scale : Integer;
   private var _size : integer;
   private var _sourceColumn : String;

   // Public Accessor methods.
   public function get DbType() : String {
      return this._dbType;
   }
   public function get Direction() : String {
      return this._direction;
   }
   public function get Name() : String {
      return this._name;
   }
   public function get Precision() : Integer {
      return this._precision;
   }
   public function get ProviderType() : String {
      return this._providerType;
   }
   public function get Scale() : Integer {
      return this._scale;
   }
   public function get Size() : Integer {
      return this._size;
   }
   public function get SourceColumn() : String {
      return this._sourceColumn;
   }

   // Constructor.
   function Param(item) {
      this._name = item.Name;
      this._precision = item.NumericPrecision;
      this._scale = param.NumericScale;
      
      this.DbType = item.TypeName;
      this.Direction = item.Direction;
      this.ProviderType = item.TypeName;
      SetSize(item.TypeName, item.NumericPrecision, item.CharacterMaxLength);
      SetSourceColumn(item.Direction, item.Name);
   }

   // Internal Setter methods.
   protected function set DbType(type : String) {
      if (type == \"\")
         throw \"You can't have a blank DbType!\";
      switch(type) {
         case \"float\":
            this._dbType = \"Double\";
            break;
         case \"int\":
            this._dbType = \"Int32\";
            break;
         case \"money\":
            this._dbType = \"Currency\";
            break;
         case \"nvarchar\":
            this._dbType = \"String\";
            break;
         case \"real\":
            this._dbType = \"Single\";
            break;
         case \"timestamp\":
            this._dbType = \"Binary\";
            break;
         default:
            this._dbType = type;
      }
   }

   protected function set Direction(dir : String) {
      this._direction = iif(dir = \"RETURN\", \"ReturnValue\", \"Input\");
   }

   protected function set ProviderType(type : String) {
      this._providerType = PCase(type);
   }

   protected function SetSize(type : String, precision : Integer, maxLength: Integer) {
      switch(type) {
         case \"int\":
         case \"real\":
            this._size = 4;
            break;

         case \"float\":
         case \"money\":
         case \"timestamp\":
            this._size = 8;
            break;

         case \"nvarchar\":
            this._size = maxLength;
         default:
            this._size = 4;
      }
   }

   protected function SetSourceColumn(dir : String, name : String) {
      this._sourceColumn = \"\";
      if (dir != \"RETURN\") {
         this._sourceColumn = \" SourceColumn=\\\"\" + name.replace(/@/g, \"\") + \"\\\"\";
      }
   }
}
davidtar
Lurker
 
Posts: 1
Joined: Fri Dec 08, 2006 1:37 am

Postby justin.greenwood on Fri Dec 08, 2006 2:43 am

the JScript templates are not JScript.Net compliant. If you're generating JScript for some custom stuff you're doing in a browser, you really can't be using any of the fancy framework classes or new keywords if you want to be cross browser compliant.

Look here:
http://msdn2.microsoft.com/en-us/library/2z6exc9e.aspx
It shows the new features of JScript 8.0 to be supported only by the .net framework, not any browsers. IE 6 supports JScript 5.6. I'm fairly certain our JScript templates run under the same version. Just look at the feature matrix under there and you'll get a feel for what you can and can't do.
User avatar
justin.greenwood
Site Admin
 
Posts: 441
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN


Return to General Template Questions/Comments

Who is online

Users browsing this forum: No registered users and 1 guest

cron