<html>
<body>
<input type="button" name="name" value="xxxx" οnclick="test()"/>
</body>
<script language="javascript">
var person = {name:"张三",sex:"男",age:"13",address:[{p:"粤",c:"深",s:"南京路"},{p:"湘",c:"长",s:"西御街"}],testclick:function(){alert("hello world!")}};
function student(){alert("student");}
person.student =student;
//匿名函数
(function(x){//x是形参
function a(){//a是私有方法,如果不赋值到外部可见的变量上,外部将不能调用a
return {
b:b,
c:x+"x"
}
}
function b(){
alert("b");
}
person.a = a;//把a添加到person上,让外部可以调用a
})("a");//实参
//回调函数
function func(a,b,callback){
var num = a-b;
callback(num);
}
function test(){
alert(person.age);//13
alert(person.address[1].c);//长
alert(person.testclick);//function(){alert("hello world!")}
var t = person.testclick;
t();//hello world!
person.student();//student
var t1 = person.a();
t1.b();//b
alert(t1.c);//ax
func(8,2,function(num){
alert(num);//6
});
}
</script>
</html>