uhop / dcl

Elegant minimalistic implementation of OOP with mixins + AOP in JavaScript for node.js and browsers.
http://www.dcljs.org/
Other
76 stars 10 forks source link

Wrong amount of arguments #3

Closed clubajax closed 7 years ago

clubajax commented 11 years ago

When I try to make a simple class:

dcl({constructor:function(){}});

I get a very cryptic error, "Uncaught TypeError: Cannot read property 'constructor' of undefined"

One of two things would help here: handle that use case (my preferred), or do a check for the correct arguments to throw a warning and log the object so it's easier to find the offender. I did this on line 19 in mini.js:

if(typeof superClass === 'object' && !props){
    var disp = superClass && superClass.declaredClass ? superClass.declaredClass : superClass;
    var msg = 'Wrong amount of arguments used for DCL';
    console.error(msg, superClass);
    throw new Error(msg);
}
uhop commented 11 years ago

It should be:

dcl(null, {constructor:function(){}});

In general it sounds like a good candidate for debug.js, which was specifically created to keep all useful debugging facilities separate.

clubajax commented 11 years ago

Yes, that would be good. Is there any reason to not create the class I showed? Why do you have to specifically show that you do not have any dependencies?

uhop commented 11 years ago

The reason is simple: it is hard to make a mistake in two-argument function. Bypassing a check for that saves on CPU time, space, and bandwidth.

uhop commented 7 years ago

Addressed in 2.0.