xiangfei01 发表于 2011-12-22 08:54

JavaScript高级培训-自定义对象

<span class="Apple-style-span" style="font-family: 'Trebuchet MS', Arial, 'Lucida Sans Unicode', Tahoma, sans-serif; line-height: normal; "><p><strong><font size="5">一,概述</font></strong></p><p>在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类、Hashtable类等等。</p><p>目前在Javascript中,已经存在一些标准的类,例如Date、Array、RegExp、String、Math、Number等等,这为我们编程提供了许多方便。但对于复杂的客户端程序而言,这些还远远不够。</p><p>与Java不同,Java2提供给我们的标准类很多,基本上满足了我们的编程需求,但是Javascript提供的标准类很少,许多编程需求需要我们自己去实现,例如Javascript没有哈西表Hashtable,这样的话在处理键值方面就很不方便。</p><p>因此,我个人认为一个完整的Javascript对象视图应该如下:</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineview.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p><strong><font size="5">二,基本概念</font></strong></p><p>1,自定义对象。<br>根据JS的对象扩展机制,用户可以自定义JS对象,这与Java语言有类似的地方。<br>与自定义对象相对应的是JS标准对象,例如Date、Array、Math等等。<br>2,原型(prototype)<br>在JS中,这是一种创建对象属性和方法的方式,通过prototype可以为对象添加新的属性和方法。<br>通过prototype我们可以为JS标准对象添加新的属性和方法,例如对于String对象,我们可以为其添加一个新的方法trim()。<br>与严格的编程语言(例如Java)不同,我们可以在运行期间为JS对象动态添加新的属性。</p><p><strong><font size="5">三,语法规则</font></strong></p><p>1,对象创建方式</p><p>1)对象初始化器方式</p><p>格式:objectName = {property1:value1, property2:value2,…, propertyN:valueN}&nbsp;<br>property是对象的属性<br>value则是对象的值,值可以是字符串、数字或对象三者之一<br>例如: var user={name:“user1”,age:18};<br>&nbsp;&nbsp;&nbsp; var user={name:“user1”,job:{salary:3000,title:programmer}<br>以这种方式也可以初始化对象的方法,例如:<br>&nbsp;&nbsp;&nbsp; var user={name:“user1”,age:18,getName:function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; }<br>后面将以构造函数方式为重点进行讲解,包括属性和方法的定义等等,也针对构造函数的方式进行讲解。</p><p><span id="more-94"></span></p><p>2)构造函数方式</p><p>编写一个构造函数,并通过new方式来创建对象,构造函数本可以带有构造参数<br>例如:<br>function User(name,age){&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age=age;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.canFly=false;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; var use=new User();</p><p>2,定义对象属性</p><p>1)JS中可以为对象定义三种类型的属性:私有属性、实例属性和类属性,与Java类似,私有属性只能在对象内部使用,实例属性必须通过对象的实例进行引用,而类属性可以直接通过类名进行引用。</p><p>2)私有属性定义<br>私有属性只能在构造函数内部定义与使用。<br>语法格式:var propertyName=value;<br>例如:<br>function User(age){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age=age;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var isChild=age&lt;12;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.isLittleChild=isChild;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; var user=new User(15);<br>&nbsp;&nbsp;&nbsp; alert(user.isLittleChild);//正确的方式<br>&nbsp;&nbsp;&nbsp; alert(user.isChild);//报错:对象不支持此属性或方法</p><p>3)实例属性定义,也存在两种方式:<br>prototype方式,语法格式:functionName.prototype.propertyName=value<br>this方式,语法格式:this.propertyName=value,注意后面例子中this使用的位置<br>上面中value可以是字符创、数字和对象。<br>例如:<br>function User(){ }<br>User.prototype.name=“user1”;<br>User.prototype.age=18;<br>var user=new User();<br>alert(user.age);<br>—————————————–<br>function User(name,age,job){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=“user1”;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age=18;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.job=job;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; alert(user.age);</p><p>3)类属性定义<br>语法格式:functionName.propertyName=value<br>例如:<br>function User(){ }<br>User.MAX_AGE=200;<br>User.MIN_AGE=0;<br>alert(User.MAX_AGE);<br>参考JS标准对象的类属性:<br>Number.MAX_VALUE //最大数值 Math.PI //圆周率</p><p>4)对于属性的定义,除了上面较为正规的方式外,还有一种非常特别的定义方式,语法格式: obj=value<br>例子:<br>&nbsp;&nbsp;&nbsp;&nbsp; function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age=18;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this=“ok”;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this=“year”;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; var user=new User(“user1”);<br>&nbsp;&nbsp;&nbsp;&nbsp; alert(user);<br>&nbsp;&nbsp;&nbsp;&nbsp; 在上面例子中,要注意:不同通过this来获取age属性,也不能通过this来获取name属性,即通过index方式定义的必须使用index方式来引用,而没有通过index方式定义的,必须以正常方式引用</p><p>3,定义对象方法</p><p>1)JS中可以为对象定义三种类型的方法:私有方法、实例方法和类方法,与Java类似:<br>私有方法只能在对象内部使用<br>实例方法必须在对象实例化后才能使用<br>类方法可以直接通过类名去使用<br>注意:方法的定义不能通过前面所说的index方式进行。<br>2)定义私有方法<br>私有方法必须在构造函数体内定义,而且只能在构造函数体内使用。<br>语法格式:function methodName(arg1,…,argN){ }<br>例如:<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function getNameLength(nameStr){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nameStr.length;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.nameLength=getNameLength(this.name);&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; }<br>3)定义实例方法,目前也可以使用两种方式:<br>prototype方式,在构造函数外使用,语法格式:<br>functionName.prototype.methodName=method;<br>或者<br>functionName.prototype.methodName=function(arg1,…,argN){};<br>this方式,在构造函数内部使用,语法格式:<br>this.methodName=method;<br>或者<br>this.methodName=function(arg1,…,argN){};<br>上面的语法描述中,method是外部已经存在的一个方法,methodName要定义的对象的方法,意思就是将外部的一个方法直接赋给对象的某个方法。<br>以function(arg1,…,argN){}的方式定义对象方法是开发人员应该掌握的。</p><p>定义实例方法的一些例子:例子1<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.getName=getUserName;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.setName=setUserName;<br>}<br>function getUserName(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<br>}<br>Function setUserName(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>}</p><p>定义实例方法的一些例子:例子2<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.getName=function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.setName=function(newName){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=newName;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>}</p><p>定义实例方法的一些例子:例子3<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>}<br>User.prototype.getName=getUserName;<br>User.prototype.setName=setUserName();<br>function getUserName(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<br>}<br>Function setUserName(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>}</p><p>定义实例方法的一些例子:例子4<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>}<br>User.prototype.getName=function(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.name;<br>};<br>User.prototype.setName=function(newName){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=newName;<br>};</p><p>4)定义类方法<br>类方法需要在构造函数外面定义,可以直接通过构造函数名对其进行引用。<br>语法格式:<br>functionName.methodName=method;<br>或者<br>functionName.methodName=function(arg1,…,argN){};<br>例子:<br>function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; User.getMaxAge=getUserMaxAge;<br>&nbsp;&nbsp;&nbsp; function getUserMaxAge(){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 200;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; 或者<br>&nbsp;&nbsp;&nbsp; User.getMaxAge=function(){return 200;};<br>&nbsp;&nbsp;&nbsp; alert(User.getMaxAge());</p><p>4,属性与方法的引用</p><p>1)从可见性上说:<br>私有属性与方法,只能在对象内部引用。<br>实例属性与方法,可以在任何地方使用,但必须通过对象来引用。<br>类属性与方法,可以在任何地方使用,但不能通过对象的实例来引用(这与Java不同,在Java中静态成员可以通过实例来访问)。<br>2)从对象层次上说:<br>与Java bean的引用类似,可以进行深层次的引用。<br>几种方式:<br>简单属性:obj.propertyName<br>对象属性:obj.innerObj.propertyName<br>索引属性:obj.propertyName<br>对于更深层次的引用与上面类似。<br>3)从定义方式上说:<br>通过index方式定义的属性,必须通过index方式才能引用。<br>通过非index方式定义的属性,必须通过正常的方式才能引用。<br>另外注意:对象的方法不能通过index方式来定义。</p><p>5,属性与方法的动态增加和删除<br>1)对于已经实例化的对象,我们可以动态增加和删除它的属性与方法,语法如下(假定对象实例为obj):<br>动态增加对象属性<br>obj.newPropertyName=value;<br>动态增加对象方法<br>&nbsp;&nbsp;&nbsp; obj.newMethodName=method或者=function(arg1,…,argN){}<br>动态删除对象属性<br>&nbsp;&nbsp;&nbsp; delete obj.propertyName<br>动态删除对象方法<br>&nbsp;&nbsp;&nbsp; delete obj.methodName<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>2)例子:<br>&nbsp;&nbsp;&nbsp; function User(name){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name=name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.age=18;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; var user=new User(“user1”);<br>&nbsp;&nbsp;&nbsp; user.sister=“susan”;<br>&nbsp;&nbsp;&nbsp; alert(user.sister);//运行通过<br>&nbsp;&nbsp;&nbsp; delete user.sister;<br>&nbsp;&nbsp;&nbsp; alert(user.sister);//报错:对象不支持该属性</p><p>&nbsp;&nbsp;&nbsp; user.getMotherName=function(){return “mary”;}<br>&nbsp;&nbsp;&nbsp; alert(user.getMotherName());//运行通过<br>&nbsp;&nbsp;&nbsp; delete user.getMotherName;<br>&nbsp;&nbsp;&nbsp; alert(user.getMotherName());//报错:对象不支持该方法</p><p><strong><font size="5">四,总结</font></strong></p><p>1,自定义对象机制,是JS最为吸引人的机制之一,对于C++和Java程序员而言,这简直太棒了!<br>2,对象创建存在两种方式:对象初始化器和构造函数。<br>3,对象属性和方法,具有可见性的约束,不同可见性的属性和方法,其定义方式也不一样。</p><p>&nbsp;&nbsp;<img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefinesummary.gif" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p><strong><font size="5">五,应用案例</font></strong></p><p>下面将采用一个应用案例:网上购物商城<br>应用案例的实现步骤:<br>1,场景设计</p><p>1)登录场景</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample1.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>2)购物场景</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample2.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>3)结算场景</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample3.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>2,界面设计</p><p>1)登录页面</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample4.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>2)购物页面</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample5.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>3)结算页面</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample6.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>3,类图设计</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample7.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>4,代码实现</p><p>1)Product类</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample8.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>2)ShoppingCart类</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample9.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "><br>3)ShoppingSession类</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample10.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; "></p><p>4)ShoppingCartParser类</p><p><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/eye_of_back/selfdefineexample11.jpg" style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); background-position: initial initial; background-repeat: initial initial; ">&nbsp;</p></span>
页: [1]
查看完整版本: JavaScript高级培训-自定义对象