node02-util


目录:
node01-创建服务器
node02-util
node03-events
node04-buffer
node05-fs
node06-path
node07-http
node08-express
node09-cookie

util模块:

 1 var util = require("util");
 2 /*
 3 * 1、实现继承
 4 * 2、对象的序列化
 5 * 3、检测数据类型
 6 * */
 7 
 8 //实现继承
 9 function Paa(){
10     this.name = "zy";
11     this.age = "23";
12     this.sayHello = function(){
13         console.log("hello");
14     }
15 }
16 Paa.prototype.say = function(){
17     console.log(this.name);
18 }
19 var paa = new Paa();
20 // paa.say();
21 
22 
23 function Caa(){
24     this.name = "yz";
25     this.age = "22";
26 }
27 util.inherits(Caa,Paa);//原型继承
28 var caa = new Caa();
29 // caa.say();
30 // console.log(caa.age);//没有
31 
32 
33 //对象的序列化
34 console.log(typeof util.inspect(caa));//转化为字符串
35 
36 //检测数据类型
37 // console.log(typeof []);
38 console.log(util.isArray([]));
39 console.log(util.isObject([]));
View Code

 node学习02

原文地址:https://www.cnblogs.com/98-bky/p/6188231.html