您的位置:首页 > Web前端 > JavaScript

面向对象的JavaScript学习笔记

2009-06-10 22:39 399 查看
最近在看《PPK谈JavaScript》以及《精通JavaScript》,对这门脚本语言的理解深了很多,相信将来会变得更加的强大!







Code

//overload testing 函数重载
function sendMsg(msg,obj)
{
if(arguments.length==2)
obj.handleMsg(msg);
else
alert(msg);
}
sendMsg("Hello, World!");
sendMsg("How are you!",{
handleMsg:function(msg)
{
alert("This is a custom msg:"+msg);
}
});


//type checkging 类型检查
var strTest="test";
var aryTest=[];
alert(strTest.constructor);
alert(aryTest.constructor);
alert(typeof strTest);
alert(typeof(aryTest));
alert(aryTest.constructor==Array);

//make arry function 生成数组
function makeArray()
{
var arr=[];
for(var i=0;i<arguments.length;i++)
{
arr.push(arguments[i]);
}
return arr;
}

//privileged method 特权方法
function User(name,age)
{
var year=(new Date()).getFullYear()-age;
this.getBornYear=function(){
return year;
};
}
var user=new User("Li",23);
alert(user.getBornYear());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: