??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>http://www.aygfsteel.com/ynstudio/articles/70245.html一?/dc:creator>一?/author>Mon, 18 Sep 2006 03:43:00 GMThttp://www.aygfsteel.com/ynstudio/articles/70245.htmlhttp://www.aygfsteel.com/ynstudio/comments/70245.htmlhttp://www.aygfsteel.com/ynstudio/articles/70245.html#Feedback0http://www.aygfsteel.com/ynstudio/comments/commentRss/70245.htmlhttp://www.aygfsteel.com/ynstudio/services/trackbacks/70245.html对于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. * PolymorphismQ多态)- The ability for two classes to respond to the same (collection of) methods. * Inheritance Q承)- The ability to define the behavior of one object in terms of another by sub-classing. 在javascript里都可实现?br />感觉对于理解javascript的面向对象特性,有这样几炚w要注意, 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(){ this.x = "abc"; this.sayHello1 = function(){alert("hello你个_");} }; Foo.sayHello2 = function(){alert("你hello个头Q?);}
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