我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp未分类 > 使用JScript.NET创建asp.net页面(四)
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

使用JScript.NET创建asp.net页面(四) 

作者:佚名   来源:一亩三分地   点击:   日期:2007-03-30

在Jscript中定义类通过类声明, 包含方法和对象和var 声明。对于类的派生通过下面两个程序的对比,你讲清楚地明白。
    JScript 5.5 Code
// Simple object with no methods
function Car(make, color, year)
{
   this.make = make;
   this.color = color;
   this.year = year;
}
function Car.prototype.GetDescription()
{
   return this.year + " " + this.color + " " + this.make;
}
// Create and use a new Car object
var myCar = new Car("Accord", "Maroon", 1984);
print(myCar.GetDescription());
JScript.NET Code
// Wrap the function inside a class statement.
class Car
{
   var make : String;
   var color : String;
   var year : int;
   function Car(make, color, year)
   {
      this.make = make;
      this.color = color;
      this.year = year;
   }
   function GetDescription()
   {
      return this.year + " " + this.color + " " + this.make;
   }
}
var myCar = new Car("Accord", "Maroon", 1984);
print(myCar.GetDescription());
    Jscript.net还支持定义private和protected property通过GET和SET进行读写。
如下例:
class Person
{
   private var m_sName : String;
   private var m_iAge : int;
   function Person(name : String, age : int)
   {
      this.m_sName = name;
      this.m_iAge = age;
   }
   // Name 只读
   function get Name() : String
   {
      return this.m_sName;
   }
   // Age 读写但是只能用SET
   function get Age() : int
   {
      return this.m_sAge;
   }
   function set Age(newAge : int)
   {
      if ((newAge >= 0) && (newAge <= 110))
         this.m_iAge = newAge;
      else
         throw newAge + " is not a realistic age!";
   }
}
var fred : Person = new Person("Fred", 25);
print(fred.Name);
print(fred.Age);
// 这将产生一个编译错误,name是只读的。
fred.Name = "Paul";
// 这个将正常执行
fred.Age = 26;
// 这将得到一个 run-time 错误, 值太大了
fred.Age =




文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·给你的FileSystemObject对象加把锁 ·在 Web 页上使用条件数值格式
·连接数据库查询手册(不仅仅适用于asp) ·警惕"给你的FileSystemObject对象加把锁"
·用ASP做全文检索 ·如何把ASP编写成DLL

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。