手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >在Javascript中定义对象类别
在Javascript中定义对象类别
摘要:From:JavaEye.com注意JavaScript中对象类别的定义,使用function来定义对象类别,初始化对象使用new操作符fu...

From:JavaEye.com

注意JavaScript中对象类别的定义,使用function来定义对象类别,初始化对象使用new操作符

functionPerson(name,age){

this.name=name;

this.age=age;

this.toString=function(){

document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);

}

}

完整的简单HTML

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>

<title>JavaScript</title>

<scriptlanguage="javascript"type="text/javascript">

functionPerson(name,age){

this.name=name;

this.age=age;

this.toString=function(){

document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);

}

}

</script>

</head>

<body>

<scripttype="text/javascript">

varperson=newPerson();

person.name="robbin";

person.age=30;

person.toString();

</script>

</body>

</html>

【在Javascript中定义对象类别】相关文章:

JavaScript中for循环的使用详解

javascript中一些util方法汇总

JavaScript中Math.SQRT2属性的使用详解

详解JavaScript中void语句的使用

基于javascript简单实现对身份证校验

详解Javascript中的Object对象

由浅到深了解JavaScript类

在HTML中插入JavaScript代码的示例

JavaScript中的私有成员

JavaScript中reduce()方法的使用详解

精品推荐
分类导航