漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
http://www.codeproject.com/jscript/
http://www.codeproject.com/aspnet/ProMatrixUnplugged3.asp
<H2>Concepts of OO JavaScript with ASP.NET</H2>
<P nd="38">Many people don't know that JavaScript can be used in an object
oriented programming fashion, and thus, they don't consider using it for actual
business objects. This is important to know to keep the business objects on the
client, instead of on the server. Below is a short example of how to create a
business object called "<CODE nd="39">Employee</CODE>". In its constructor, it
populates some property, and has a method called "<CODE
nd="40">displayDetails</CODE>".</P>
<P nd="41">Example:</P>
<DIV class=precollapse id=premain2 style="WIDTH: 100%"><IMG id=preimg2
style="CURSOR: hand" height=9 src="http://www.codeproject.com/images/minus.gif"
width=9 preid="2"> Collapse</DIV><PRE lang=jscript id=pre2 style="MARGIN-TOP: 0px" nd="43">onload = function (){ window_onload(); };
 
 function window_onload()
 {
     emp1 = new Employee("Mary", "Q", "Harris", "Accounting");
     emp2 = new Employee("Thomas", "O", "Williams", "Shipping");
 
     emp1.displayDetails();
     emp2.displayDetails();
 }
 
 /* Constructor function for using an Employee object.*/
 function Employee(firstName, middleInitial, lastName, department)
 {
     this.firstName = firstName;
     this.middleInitial = middleInitial;
     this.lastName = lastName;
     this.department = department;
 }
 
 /* defining an Employee method called
    displayDetails which takes no arguments */
 Employee.prototype.displayDetails = function ()
 {
     alert(" first name: " + this.firstName + "\r\n last name: " +
           this.lastName + "\r\n department: " + this.department);
 }</PRE>
posted on 2006-12-06 16:10  javaca88  阅读(125)  评论(0)    收藏  举报