当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript中Object和Function的关系小结

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 JavaScript中Object和Function的关系小结


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

JavaScript 中 Object 和 Function 的关系是微妙的,他们互为对方的一个实例。 Function instanceof Object 和 Object instanceof Function 都是 true
1。我们可以认为 Object 是一个特殊的“类”,而这里的“类”即:Function
于是便可以理解为: Object = Function () {} 或 Object = new Function(); 即:Object 是 Function 的一个实例,所以,Object 原型链中便包含 Function.prototype,得出: Function.prototype.isPrototypeOf(Object) 为 true
2。同时,js中,所有对象(不包括js语言外部对象)都可视为是 Object 的一个实例, Function 不例外,Function.prototype 亦不例外,于是有 Function = new Object(); Function.prototype = new Object(), 于是 Object.prototype.isPrototypeOf(Function) 和 Object.prototype.isPrototypeOf(Function.prototype) 都为 true 了
3。补充:Function 本身也是一个“类”,然而,所有“类”都是Funciton的实例,于是 Function instanceof Function; 为true。同时,所有对象都是 Object 类的实例,Object 本身也是一个对象,所有又有 Object instanceof Object 也为 true。另外,还可以认为 Funciton 类型是 Object 类型的一个“派生类”,class Function 继承了class Object ,是 class Object 的一个“子类”。