日期:2014-05-16 浏览次数:20429 次
var noLog = true; // release version
// noLog = false; // development version
log( noLog ? null : getName());
//all your log line, should have a form:
log ( noLog ? null : messageExpression );
//By this trick, when noLog is false, messageExpression will not be executed!
log= function () {
if(arguments.length==1 && typeof arguments[0] !="function"){
console.log(arguments[0]);
return;
}
var back;
if(typeof arguments[0] =="function"){
console.log(Array.slice(arguments,1));
back =arguments[0].apply(arguments[0],Array.slice(arguments,1));
}else if(arguments.length>2 && (typeof arguments[1] =="function")){
var fn = arguments[1];
var args= Array.slice(arguments,2);
back =fn.apply(arguments[0],args);
}
console.log(back);
return back;
}
/*********************************/
function test() {
console.log("test is run!!");
return "test";
}
function sum(a ,b) {
console.log("sum is run!!");
return a+b;
}
var person={
age:10,
say:function (str) {
return str + this.age;
}
};
log("Test start!");
log(test);
log(sum,10,100);
log(person,person.say,"My age is");