js对象
来源:互联网 发布:java域对象是什么意思 编辑:程序博客网 时间:2024/06/01 04:00
对象里var的是私有的 this.的是公有的
<html>
<script>
function User()
{
this.name="";
this.age="";
this.getName=function()
{
return this.name;
}
this.getAge=function()
{
return this.age;
}
this.setName=function(name)
{
this.name=name;
}
this.setAge=function(age)
{
this.age=age;
}
this.introduction=function()
{
alert("My name is" + this.name+"/n" +"age is" +
this.age);
}
}
var user1=new User();
user1.setName("qqq");
user1.setAge("11");
user1.introduction();
alert("My name is" + user1.name+"/n" +"age is" + user1.age);
</script>
</html>
<html>
<script>
var Person={};
Person.name="Tom";
Person["age"]=20;
Person.introduction=function()
{
alert("My name is "+this.name+",my age is
"+this.age);
};
Person.introduction();//My name is Tom age is 20
for(var field in Person)
{
alert("field name:" + field + ";value:" +Person
[field]);
delete Person.name;
Person.introduction();
alert(name in Person);//false
}
</script>
</html>
<html>
<script>
function hello()
{
alert("Hello!");
}
hello.name="Tom";//添加属性
alert(hello["name"]);
delete hello.name;//删除属性
alert(hello.name);
//赋值给变量
var hello1=function()
{
alert(hello1);
};
hello1();
//作为数组元素
function show1(x)
{
alert(x);
}
var arr=[show1];
arr[0](5);
//作为函数的参数
function callFunc(func)
{
func();
}
callFunc(function()
{
alert("Inner function.");
});
function show()
{
return function(n){alert("number is "+n)};
}
show()(10);
alert(arr[0]);
</script>
</html>
- Js 对象
- js 对象
- js对象
- js对象
- js 对象
- js对象
- js对象
- JS 对象
- js对象
- Js 对象
- js对象
- JS对象
- JS 对象
- js对象
- Js对象
- js 对象
- js 对象
- js对象
- 如何让Activity透明
- group by语句,聚合函数与其他语句(关系,执行过程)
- iphone 导航控制器小概念
- Windows API一日一练 FindFirstFile和FindNextFile函数
- Install EditPlus on Ubuntu
- js对象
- 何为句柄
- STL实践指南(上)
- spring配置中parent和abstract作用
- 为应用“瘦身”!给 Android 应用开发者的十个建议
- 移植Linux-2.6.30.4到mini2440
- STL实践指南(中)
- Debug和Release有什么区别
- 正则式简单匹配ip地址