1
我有,我想要麼接受列表或蒙戈光標並作出反應的是一個方法,例如:檢查,如果對象是一個蒙戈光標
createFromTemplate: function(template) {
var iter;
if(template instanceof Mongo.Cursor) {
iter = template.fetch();
} else if(template instanceof Array) {
iter = template;
} else {
throw new Meteor.Error(500, 'Template must be a Cursor or Array');
}
}
但是,它似乎返回false時我不指望它
> var p = PageTemplates.find(); // as a mongo cursor
> var pArray = p.fetch(); // as an array
> Object.prototype.toString.call(p);
[object Object]
> typeof p
Object
> p instanceof Mongo.Cursor
false
如何判斷對象是否是Mongo遊標?