Mô- đun sử dụng Node.js
Ví dụ
Định dạng chuỗi bằng cách sử dụng các đối số "Linus" và "6":
var util = require('util');
var txt = 'Congratulate %s on his %dth
birthday!';
var result = util.format(txt, 'Linus', 6);
console.log(result);
Chạy ví dụ »Định nghĩa và cách sử dụng
Mô-đun Util cung cấp quyền truy cập vào một số chức năng tiện ích.
Cú pháp
Cú pháp để đưa mô-đun Util vào ứng dụng của bạn:
var util = require('util');
Sử dụng thuộc tính và phương thức
Method | Description |
---|---|
debuglog() | Writes debug messages to the error object |
deprecate() | Marks the specified function as deprecated |
format() | Formats the specified string, using the specified arguments |
inherits() | Inherits methods from one function into another |
inspect() | Inspects the specified object and returns the object as a string |