Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kareem prevent me from adding custom method to Object.prototype #7

Closed
menemsalama opened this issue Sep 24, 2016 · 7 comments
Closed

Comments

@menemsalama
Copy link

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)

@vkarpov15
Copy link
Member

Can you provide a more thorough code sample?

@menemsalama
Copy link
Author

menemsalama commented Sep 27, 2016

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. ({MYPATH}\drello\models\user.js:19:27
)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object. ({MYPATH}\drello\app.js:12:25)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3

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

@vkarpov15
Copy link
Member

Yeah I'm going to close this for now because this issue's pretty stale and OP was never really clear about the issue.

@jo-russ
Copy link

jo-russ commented Nov 30, 2016

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.

@vkarpov15
Copy link
Member

Yes please, provide more details, preferably a script that lets me repro the issue. Prose descriptions always fail to properly convey code issues.

@jo-russ
Copy link

jo-russ commented Dec 1, 2016

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()

vkarpov15 added a commit that referenced this issue Dec 9, 2016
vkarpov15 added a commit to Automattic/mongoose that referenced this issue Dec 9, 2016
@vkarpov15
Copy link
Member

Fixed, thanks for the repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants