util.promisify((arg, resolve, reject) => {
doSomething(foo, resolve);
});
// 原本假設 doSomething 要執行第二個參數當作
// callback 時就會去執行 resolve
var util = require('util');
function Base() {
this.sayHello = function() {
console.log('Hello ' + this.name);
};
}
Base.prototype.showName = "as";
function Sub() {
this.name = 'sub';
}
util.inherits(Sub,Base);
var dd = new Sub();
console.log(dd.showName);
console.log(Sub.prototype.sayHello);
var util = require('util');
function Person() {
this.name = 'byvoid';
this.toString = function() {
return this.name;
};
}
var obj = new Person();
var as = {
a:12
};
console.log(util.inspect(as));
console.log(util.inspect(Person,true)); //如果沒有true只會顯示他是個function
var util = require('util');
console.log(util.isArray([]));
console.log(util.isArray(new Array));
console.log(util.isArray({}));
var util = require('util');
console.log(util.isRegExp(/some regexp/));
console.log(util.isRegExp(new RegExp('another regexp')));
console.log(util.isRegExp({}));
var util = require('util');
console.log(util.isDate(new Date()));
console.log(util.isDate(Date())); //沒有new會返回字串
console.log(util.isDate({}));
var util = require('util');
util.isError(new Error())
// true
util.isError(new TypeError())
// true
util.isError({ name: 'Error', message: 'an error occurred' })
// false