??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产第一页,日本欧美韩国一区三区,中文字幕视频在线观看http://www.aygfsteel.com/ynstudio/category/15261.html主要是JavaEE和Ajaxzh-cnWed, 28 Feb 2007 00:32:34 GMTWed, 28 Feb 2007 00:32:34 GMT60关于javascript的面向对?/title><link>http://www.aygfsteel.com/ynstudio/articles/70245.html</link><dc:creator>一?/dc:creator><author>一?/author><pubDate>Mon, 18 Sep 2006 03:43:00 GMT</pubDate><guid>http://www.aygfsteel.com/ynstudio/articles/70245.html</guid><wfw:comment>http://www.aygfsteel.com/ynstudio/comments/70245.html</wfw:comment><comments>http://www.aygfsteel.com/ynstudio/articles/70245.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ynstudio/comments/commentRss/70245.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ynstudio/services/trackbacks/70245.html</trackback:ping><description><![CDATA[ <div class="wmqeeuq" id="show928" class="postcontent">对于javascript的面向对象有不少说法Q有的说Qjavascript不是面向对象的,有的说javascript是基于对象的Q有的说使用javascript可以实现面向对象?br />? 查阅了一些资料,包括ECMAscript Language Specification Edition 3 24-Mar-00Q似乎应该说成javascript是基于原型(prototype-based Q的面向对象Q而C++Qjava之类的是Zcȝ面向对象Q即面向对象的实现方式不同。面向对象ƈ不必然是Zclass的。一文章中提到的面向对? 最主要的三个特?br /> * EncapsulationQ封装) - Support for method calls on a Javascript object as a member of a Class.<br /> * PolymorphismQ多态)- The ability for two classes to respond to the same (collection of) methods.<br /> * Inheritance Q承)- The ability to define the behavior of one object in terms of another by sub-classing.<br />在javascript里都可实现?br />感觉对于理解javascript的面向对象特性,有这样几炚w要注意,<br />1、将面向对象作ؓ一个独立的通用概念Q面向对象有不同的实现方式,也有不同的扩展。C++的面向对象和java不完全相同,javascript和他们也不完全相同?br />2、对于javaE序员需要知道javascript里的对象和java里所谈的对象Q实例)有很大不同?br />3、函C是对象,是可以作为构造器的对象,是可以生对象的对象。因为javascript里所谓对象就是指属性的无序集合。函数可以添加属性,所以也是对象?br />4、进一步了解new和prototype的定义?br />5? 再对javaE序员说一句,对象Q在javascript里非函数的对象,最cMjava里的对象Q实例)Qjava里对象有属性,有方法,? javascript里对象只有属性,所谓的Ҏ是函数cd的属性,引用一般属性可以写成o.xQ也可以写成o["x"]Q用对象的Ҏ也同样o.f ()可以Qo["f"]()也可以。另外你所引用的对象的属性可以是对象本n的属性,也可以是该对象的构造函数的原型的属性?br />6、我以前L对照java来理解javascriptQ但现在看理解了C++或C的函数指针的概念Q将javascriptcLC或C++g更自然些?br />具体一点说Q?br />? 某函数对象比如Foo执行new操作Ӟ首先会生成一个新对象Q一个非函数cd的对象,然后执行FooQ在Foo的函C中,this代指新创建的函数Q? q种操作UCؓ函C为构造器QconstructorQ用,接着q会该对象与Foo的原型(PrototypeQ徏立联pR?br />var Foo = function(){<br /> this.x = "abc";<br /> this.sayHello1 = function(){alert("hello你个_");}<br />};<br />Foo.sayHello2 = function(){alert("你hello个头Q?);}<br /><br />Foo.prototype.sayHello3 = function(){alert("你个头helloQ?);}<br /><br />var foo = new Foo;<br />foo.sayHello4 = function(){alert("晕!");};<br />foo.sayHello1();<br />//如果把Foo当作cd义的话,sayHello2可以被理解ؓ静态方?br />//但和java不同的是Qfoo.sayHello2();׃抱错?br />Foo.sayHello2();<br />//在foo的属性里q没有sayHello3q个函数对象Q但在foo的构造函数的<br />//原型对象里有q个函数属性,所以可以这么来调用Q如果foo的构造函数的<br />//原型对象里也没这个属性的话,׃到这个原型对象的构造函?br />//的原型对象里LQ以此类推。本例没有体现这一点,今天太晚了,<br />//下一里Q我会在介绍javascript的几个面向对象的实现方式里写个这L例子?br />foo.sayHello3();<br />foo.sayHello4();<br />foo["sayHello4"]();<br />alert(foo.x); <br /></div> <div> </div> <img src ="http://www.aygfsteel.com/ynstudio/aggbug/70245.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ynstudio/" target="_blank">一?/a> 2006-09-18 11:43 <a href="http://www.aygfsteel.com/ynstudio/articles/70245.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>换个角度看javascript--数据cdhttp://www.aygfsteel.com/ynstudio/articles/70053.html一?/dc:creator>一?/author>Sat, 16 Sep 2006 09:03:00 GMThttp://www.aygfsteel.com/ynstudio/articles/70053.htmlhttp://www.aygfsteel.com/ynstudio/comments/70053.htmlhttp://www.aygfsteel.com/ynstudio/articles/70053.html#Feedback0http://www.aygfsteel.com/ynstudio/comments/commentRss/70053.htmlhttp://www.aygfsteel.com/ynstudio/services/trackbacks/70053.html
首先对javascript的类型再熟悉一?/strong>

javascript中变?variable)的?value)有这样几U类?type)Q?br />(ECMAscript Language Specification Edition 3 24-Mar-00)
8.1 The Undefined Type
The
Undefined type has exactly one value, called undefined. Any variable
that has not been assigned a value has the value undefined.
8.2 The Null Type
The Null type has exactly one value, called null.
8.3 The Boolean Type
The Boolean type represents a logical entity having two values, called true and false.
8.4 The String Type
The String type is the set of all finite ordered sequences of zero or more 16-bit unsigned integer values
(“elements?.
8.5 The Number Type
The Number type has exactly 18437736874454810627 (that is, 264?53+3) values, representing the doubleprecision
64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic,
except that the 9007199254740990 (that is, 253?) distinct “Not-a-Number?values of the IEEE Standard are
represented in ECMAscript as a single special NaN value. (Note that the NaN value is produced by the program
expression NaN, assuming that the globally defined variable NaN has not been altered by program execution.)
8.6 The Object Type
An Object is an unordered collection of properties. Each property consists of a name, a value and a set of attributes.

我们比较x面向对象Q所以对其中的Objectcd多加留意?br />如上面的定义QObjectcd是无序的属性的集合。每个属?property)有名Uͼ值和一些性质(attributes)Q如只读Q可枚DQ不可删Q内部的Q?br />
丑և个例子:
var a;//a现在对应一个|该值的cd?span style="FONT-WEIGHT: bold">Undefined
a = 1;//现在a对应一个Numbercd的?br />a = true;//现在a的类型变了,变成一个Booleancd的倹{?br />a = "x";//a现在对应一个Stringcd的?br />//Q注?x"和new String("x")q不相同Q?br />//说到q里惛_javascript里两个相{操作符==?==
//==只针对基本的数据cdQ不对ObjectQ如果待比较的两个值都是Object的话
//q回falseQ除非是同一个对象,如果有有一个是Object的话Q将之{化ؓ和另外一个值相同类型的?br />//然后q行比较?==则要求两者类型也相同?br />var b = new String("x");
alert(a == b);//true
alert(a===b);//false 因ؓcd不同
alert(typeof a);//string
alert(typeof b);//object
a = {};
//查看cd的方法是typeofQ可以写成typeof a也可以写成typeof(a)
//参看typeof的说?br />alert(typeof a);//object
alert(typeof true);//boolean
alert(typeof(typeof true))//string

typeof的执行逻辑

Undefined"undefined"
Null
"object"
Boolean"boolean"
Number"number"
String"string"
Object (native and doesn’t implement [[Call]])"object"
Object (native and implements [[Call]])"function"
Object (host)
Implementation-dependent

从上面可以看到对于ObjectcdQtypeofҎ值的情况q回object或function?br />Q注Q所?/span>implement [[Call]]我的理解是指是否可以作为函数调?span style="FONT-WEIGHT: bold" dragover="true">Qnative有两U一U是内置的如ArrayQDate{另一U是用户自己定义的。除此之外就是host即javascript的宿L供的一些对象。)


]]>
վ֩ģ壺 µ| | Ƽ| | ʯɽ| ԭ| ߰| Ԫ| Ѯ| п| | | | пѷ| | °Ͷ| | | | | ǿ| | | | | | | | | Դ| | | ų| ʱ| | | | ɶ| »| | |