当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Javascript 函数对象的多重身份

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 函数对象的多重身份


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

函数对象是javascript 中一个很特殊的对象,其特殊体现在他的多重身份上。
复制代码 代码如下:

function Flower()
{
this.name="rose";
this.color="red";
}
//Flower() 作为构造函数
var obj=new Flower();
//输出 true, flower 作为类引用
alert(obj instanceof Flower);

function 关键字可以声明普通函数,这一点和其他语言中函数的概念是相同的。 除此之外,他还可以用于类的声明和实现、对象的构造函数以及类的引用。
在上面的例子中通过function 关键字声明了Flower 类 ,并且通过this关键字声明了两个属性name 和color ;然后在创建obj对象时,Flower又起到了对象构造函数的作用;最后使用instanceof 关键字判断obj对象是否是Flower类的实例,此时Flower又起到了类引用的作用