1
我想要在Schema.ObjectId上定義一個新方法,這樣當我在一個Schema.ObjectId的實例上調用它時,它應該調用它。在Schema.ObjectId上定義一個方法
Schema.ObjectId.truncate = function(){
return this.toString(0,4) + this.toString(this.length-4);
}
User.findById(id, function(err, user){
console.log(user.id.truncate());
});
上面的東西(它不起作用)。
我甚至在Schema.ObjectId.prototype
上試過,但它說它沒有定義。