DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> 用nodejs實現PHP的print_r函數代碼
用nodejs實現PHP的print_r函數代碼
編輯:JavaScript綜合知識     

 這篇文章主要介紹了用nodejs實現PHP的print_r函數代碼,需要的朋友可以參考下

 代碼如下: function ergodic(obj,indentation){   var indent = "  " + indentation;   if(obj.constructor == Array || obj.constructor == Object){       for(var p in obj){       if(obj[p].constructor == Array|| obj[p].constructor == Object){         console.log(indent + "["+p+"] => "+typeof(obj)+"");         console.log(indent + "{");         ergodic(obj[p], indent);         console.log(indent + "}");       } else if (obj[p].constructor == String) {         console.log(indent + "["+p+"] => '"+obj[p]+"'");       } else {         console.log(indent + "["+p+"] => "+obj[p]+"");       }     }   } }   function print_r(obj) {   console.log("{")   ergodic(obj, "");   console.log("}") }   var stu = {'name':'Alan','grade':{'Chinese':120,'math':130,'competition':{'NOI':'First prize'}}};   print_r(stu);  
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved