随笔 - 2059  文章 - 73 评论 - 10752 trackbacks - 253

博客总目录(2007.11.12 - 2010.4.25)

posted @ 2009-05-15 22:39 万一 阅读(6596) 评论(227) 编辑
适宽查看
ASP/VBScript CakePHP-1.2 CSS-v1 CSS-v2 French
Kings and Queens Linux Command Line NaNoWriMo 2011 Six Noations 2012 Vimeo Advanced API Methods
Wikipedia HTML Character Entities HTML JavaScript Microformats
Mod Rewrite-v1 Mod Rewrite-v2 MySQL PHP-v1 PHP-v2
Python RegularExpressions-v1 RegularExpressions-v2 RGB Color Codes Ruby on Rails
SQL Server Subversion World of Warcraft

posted @ 2012-03-26 17:02 万一 阅读(667) 评论(1) 编辑

MyClass = function () {
    this.A = 1;
}

MyClass.prototype.X = function () {
    this.B = 2;
}

MyClass.prototype.Y = function () {
    this.Z = function () {
        this.C = 3;
    }
}

/* 内部对象的 this ? */
obj = new MyClass();
alert(obj.A);        //1

obj1 = new obj.X();
alert(obj1.B);       //2

obj2 = new (new obj.Y()).Z();
alert(obj2.C);       //3

/* 所属对象的 this ? */
obj = new MyClass();
obj.X();
obj.Y();
obj.Z();
alert(obj.A); //1
alert(obj.B); //2
alert(obj.C); //3

posted @ 2012-03-19 16:17 万一 阅读(531) 评论(2) 编辑

MyClass = function () {
    var A = 1;           //内部成员
    B = 2;               //内部成员
    this.C = 3;          //对象成员
}
MyClass.prototype.D = 4; //对象成员(通过原型扩展)

obj = new MyClass();
alert(obj.A); //undefined
alert(obj.B); //undefined
alert(obj.C); //3
alert(obj.D); //4

alert(obj.hasOwnProperty('C')); //true
alert(obj.hasOwnProperty('D')); //false

posted @ 2012-03-19 13:48 万一 阅读(443) 评论(3) 编辑

/* 类属性、对象属性 */
Array.Info1 = "Info1";           //为 Array 增加类属性 Info1
Array.prototype.Info2 = "Info2"; //为 Array 增加对象属性 Info2

arr = [1, 2, 3];
alert(arr.Info1);   //undefined
alert(arr.Info2);   //Info2

alert(Array.Info1); //Info1


/* 类方法、对象方法 */
Array.ShowMessage = function () { alert("ClassMessage"); };
Array.prototype.ShowMessage = function () { alert("ObjectMessage"); };

arr = [1, 2, 3];
arr.ShowMessage();   //ObjectMessage
Array.ShowMessage(); //ClassMessage

posted @ 2012-03-19 12:10 万一 阅读(432) 评论(0) 编辑

/* 值类型 */
n1 = 123;
n2 = n1;   //赋值
n2 = 456;
alert(n1); //123; n1 != n2

/* 对象类型 */
arr1 = [123];
arr2 = arr1;    //引用
arr2[0] = 456;
alert(arr1[0]); //456; arr1 === arr2

posted @ 2012-03-19 10:02 万一 阅读(429) 评论(1) 编辑
  下一页