5)构造函数的用法:
例 3.5.1
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<script>
function student(name, age)
{
/* 马克-to-win:later on we can use it in
var doc = new activexobject( "microsoft.xmldom" );
doc.async="false";
doc.load(str);
when a property has a this, means that this property is a member property.
*/
this.name = name;
this.age = age;
this.parti = function()
{
document.writeln("名字是:" + this.name + "<br>");
document.writeln("年纪是:" + this.age + "<br>");
};
}
var p = new student('jeri', 3);
document.writeln("typeof p is " + typeof(p));
//typeof(p) is object
p.parti();
p.age = 4;
p.parti();
/*the following two methods can also access some properties.*/
document.writeln("" + p["age"]);
document.writeln("" + p["a" + "ge"]);
if (p instanceof student) document.writeln("p是student的实例<br>");
/*javascript 中的对象全部是object 的子类
because this object is the topmost parent object in the prototype inheritance hierarchy, all other object classes inherit its methods and properties. it's a close enough call that javascript 2.0 may well move it into the class-based object-oriented category at which time the prototype inheritance would be replaced with super-class/sub-class mechanisms and the arguments become null and void. */
/*when the global object is created, it always has at least the following properties:
object object
function object
array object
string object
boolean object
number object
date object
math object
value properties
*/
if (p instanceof object) document.writeln("p是object的实例");
</script>
文章转载自:
如对本文有疑问, 点击进行留言回复!!
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
vert实践五——Json?Protocol Buffer?FlatBuffers?
[基于tensorflow的人脸检测] 基于神经网络的人脸检测8——验证训练好的神经网络
selenium + ajax抓取英雄联盟全部英雄的详细信息及多线程保存全部皮肤图片到本地
网友评论