日期:2014-05-16  浏览次数:20319 次

JavaScript 学习笔记 一 动态性
//动态性是指,在一个 Javascript 对象中,要为一个属性赋值,我们不必事先创建一个字段,
//只需要在使用的时候做赋值操作即可
var obj = new Object();
obj.name = "aa  ";
obj.sayHi = function()
{return "Hi "+obj.name;}

function say()
{alert(obj.sayHi());}

var objarr = new Array("cc", "aa");
var objstr = new String("hello");

// 类型的判
function handle(msg){ 
    alert(msg);
    say();
}
function handleMsg(msg,handle){
    if(handle instanceof Function)
        handle(msg);
    else
        throw new Error("the 2nd argument should be a function");
}
handleMsg("hello aa",handle);
handleMsg("hello aa"," cc");