julesfern / spahql

A query language for Javascript data. Extracted from Spah.
MIT License
325 stars 20 forks source link

Weird problem using SpahQL with PrototypeJS #22

Open pplanel opened 10 years ago

pplanel commented 10 years ago

I'm getting unwanted objects inserted in db.select response, try this:

<script src="prototype.js" type="text/javascript"></script>
<script src="spahql.min.js" type="text/javascript"></script>
<script type="text/javascript">

var db = SpahQL.db({"test":["a", "g", "o", "r", "a"]});
console.log(db.select("//test/*));

instead of returning the array of size 5 i'm getting an array of size 1600 fill of undefined properties.

julesfern commented 10 years ago

Hey @pplanel - I'm sorry I missed this, things have been a little crazy for me with moving to a new country.

I believe the problem here is that prototype.js adds a bunch of properties to the base Array.prototype and that those properties are enumerable, which means that SpahQL can't tell which properties are actual values and which are methods appended by prototype.js - this is one of the risks of monkey-patching core prototypes.

Do you also see the same problem with Object instances, or just Arrays?