Javascript 下划线uz.clone()不适用于Parse JS SDK复合查询

Javascript 下划线uz.clone()不适用于Parse JS SDK复合查询,javascript,underscore.js,parse-server,Javascript,Underscore.js,Parse Server,在Parse Server v2.3.7(包括Parse JS SDK v1.9.2)中对复合查询进行排序时,我很难做到这一点。我可以在原始查询中使用升序/降序查询方法,但当我克隆它时,它们不再工作。你知道为什么这不起作用吗?或者有没有更好的方法来克隆查询 var firstQuery = new Parse.Query('Object'); firstQuery.equalTo('property', 1); var secondQuery = new Parse.Query('Object'

在Parse Server v2.3.7(包括Parse JS SDK v1.9.2)中对复合查询进行排序时,我很难做到这一点。我可以在原始查询中使用升序/降序查询方法,但当我克隆它时,它们不再工作。你知道为什么这不起作用吗?或者有没有更好的方法来克隆查询

var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);

var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
clonedQuery.ascending('updatedAt');
// Throws error "clonedQuery.ascending is not a function"
继续此问题:

已更新 Lodash.js做了一件事,Underline.js没有。Lodash.js复制原型,而下划线.js将
prototype
设置为
undefined
。要使其与下划线.js一起工作,您需要手动复制原型:

var Parse = require('parse').Parse;
var _ = require('underscore');

var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);

var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
Object.setPrototypeOf(clonedQuery, Object.getPrototypeOf(query)); // This line is very important!
clonedQuery.ascending('updatedAt');
// This works too

嗯,我实际上使用的是下划线v1.8.3,而不是lodash。我还检查了一下,因为我使用的是parse server,所以我实际上使用的是parse v1.9.2。更新问题…我将在现有代码之外的一个单独测试中尝试一下。@enjoyjeremy。好的,即使使用下划线.js也有可能。我更新了我的答案。好吧,即使使用下划线.js也有可能。我更新了我的答案。