当前位置: 首页 > 图文教程 > 网络编程 > ASP > Object对象的一些的隐藏函数介绍

ASP
ASP调用ORACLE存储过程并返回结果集
用ASP实现网页BBS
关于Global.asa文件的深入研究与session变量失效提示的具体方法
简易ASP+注册系统
防护手册:如何防止ASP木马在服务器上运行
用Visual Basic实现多画面播放功能之二
如何增强ASP程序性能(1)
如何增强ASP程序性能(2)
如何增强ASP程序性能(3)
ASP备份数据库
二十八条改善 ASP 性能和外观的技巧
在Form域中Post大于100K的数据
如何使用ASP制作模似动态生长的表单?
Microsoft IIS 真的如此「不安全」吗?(1)
Microsoft IIS 真的如此「不安全」吗?(2)
Microsoft IIS 真的如此「不安全」吗?(3)
Microsoft IIS 真的如此「不安全」吗?(4)
Microsoft IIS 真的如此「不安全」吗?(5)
关于页面和代码分离
ServerVariables 对路径的操作

ASP 中的 Object对象的一些的隐藏函数介绍


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 190 ::
收藏到网摘: n/a

原作者:fictiony
出自:蓝色理想
自己写一套类模型的时候顺便整理出来的,贴出来给大家看看,希望能对大家有所帮助。
属性:Object.constructor
该属性被定义在类的prototype中,当对象实例创建后通过__proto__链可被对象实例所调用,并指向当前类的构造函数。以此可判断某个对象直接所属的类是哪个(与instanceof不同,instanceof并不局限于对象直接所属的类,即使是父类也返回true)。
[示例]
trace(Object.prototype.constructor == Object); //输出 true
var a = new Object();
trace(a.constructor == Object); //输出 true
var b = new Array();
trace(b.constructor == Array); //输出 true
trace(b.constructor == Object); //输出 false
trace(b instanceof Object); //输出 true
属性:Object.__constructor__
该属性功能和Object.constructor相似,区别在于它不是定义在类的prototype中的,而是当对象实例创建时附加到对象实例上的。同时,该属性也被super关键字作为父类构造函数使用时所隐含调用,用于指向父类的构造函数,即super(...)等价于 this.__constructor__.call(this, ...)。
[示例]
trace(Object.prototype.__constructor__ == Object); //输出 false
var a = new Object();
trace(a.__constructor__ == Object); //输出 true
var b = new Array();
trace(b.__constructor__ == Array); //输出 true
trace(b.__constructor__ == Object); //输出 false
方法:Object.isPrototypeOf(classFunc)
该方法用来判断当前对象是否在对象obj的__proto__链中。该方法可用来判断一个类是否另一个类的父类或子类。
[示例]
trace(Object.prototype.isPrototypeOf(new Object())); //输出 true
trace(Object.prototype.isPrototypeOf(new Array())); //输出 true
trace(Array.prototype.isPrototypeOf(new Object())); //输出 false
trace(Object.prototype.isPrototypeOf(Array.prototype)); //判断Object是否Array的父类,输出 true
方法:Object.isPropertyEnumerable(propName)
该方法用来判断名为propName的成员是否在当前对象中存在并且可被列举(使用for..in),换句话说也就是是否可见(使用ASSetPropFlags全局函数可设置对象属性是否可见)。
[示例]
var a = {x:1, y:2};
ASSetPropFlags(a, ["y"], 1); //设y为不可见
trace(a.y); //仍可输出 2
for (var i in a) trace(i); //仅输出 x
trace(a.isPropertyEnumerable("x")); //输出 true
trace(a.isPropertyEnumerable("y")); //输出 false
方法:Object.hasOwnProperty(propName)
该方法用来判断名为propName的成员是否是当前对象自己的成员,而非通过__proto__链从类的prototype中引用过来的。
[示例]
function test () {}
test.prototype.x = 1;
var a = new test();
a.y = 2;
trace(a.x); //输出 1
trace(a.hasOwnProperty("x")); //输出 false
trace(a.y); //输出 2
trace(a.hasOwnProperty("y")); //输出 true
方法:Object.toString()
该方法可定义一个对象在转换成字符串类型时所产生的字符串结果,一般定义在类的prototype中。
[示例]
function point (x, y) {
this.x = x;
this.y = y;
}
point.prototype.toString = function () {
return "[x:" + this.x + ", y:" + this.y + "]";
};
var pos = new point(10, 20);
trace("position is " + pos); //输出 position is [x:10, y:20]