Closed menemsalama closed 7 years ago
Can you provide a more thorough code sample?
Here in this script https://github.com/menemslama/drello/blob/master/sockets.js
if I wrote something like that
exports.emit = (function () {
Object.prototype.emit = function () {
console.log("Not working, and it will throw an Error in the terminal");
};
return emit;
})();
I will get this error in my terminal from "kareem"
$ node app Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal Not working, and it will throw an Error in the terminal {MYPATH}\drello\node_modules\kareem\index.js:303 n._pres[key] = this._pres[key].slice(); ^
TypeError: this._pres[key].slice is not a function
at Kareem.clone ({MYPATH}\drello\node_modules\kareem\index.
js:303:36)
at Function.compile ({MYPATH}\drello\node_modules\mongoose\
lib\model.js:3178:32)
at Mongoose.model ({MYPATH}\drello\node_modules\mongoose\li
b\index.js:392:17)
at Object.
NOTE: I will not get the error if I tried to add the custom method in the main script ( app.js ) but I will get it everywhere else
Yeah I'm going to close this for now because this issue's pretty stale and OP was never really clear about the issue.
I can provide more details if you'd like. Bit late, but I just yesteday stumbled upon the same problem.
When you add any new methods to Object object kareem somewhere inside fails on clone operation because it iterates there (for (var x in...) over object properties disregarding whether it is his own property or not (checkable via hasOwnProperty). so at some point it tries to clone function and dies.
Yes please, provide more details, preferably a script that lets me repro the issue. Prose descriptions always fail to properly convey code issues.
The simplest(-ish :D) I can think of.
var Kareem = require('kareem');
var hooks = new Kareem();
Object.prototype.dLikeABanana = function() { console.log("BANNNANAAAAA!!!"); }
var clone = hooks.clone();
var I = {};
I.dLikeABanana();
In my case it fails when used by mongoose: lib/ model.js in Model.compile()
Fixed, thanks for the repro
when I'm trying to add a custom method to Object.prototype I got this error:
TypeError: this._pres[key].slice is not a function at Kareem.clone (MYPATH\kareem\index.js:303:36)