原创文章转载请注明出处:@协思, http://zeeman.cnblogs.com
看Log4js源码有如下实现:
1 ['Trace','Debug','Info','Warn','Error','Fatal'].forEach( 2 function(levelString) { 3 this[levelString] = function(message){ 4 console.log(levelString + ":" + message); 5 } 6 } 7 );
1 ['Trace','Debug','Info','Warn','Error','Fatal'].forEach( 2 function(levelString) { 3 this[levelString] = function(message){ 4 console.log(levelString + ":" + message); 5 } 6 } 7 );