di.js icon indicating copy to clipboard operation
di.js copied to clipboard

isClass and minification

Open gah-boh opened this issue 10 years ago • 3 comments

I've been playing around with this and I believe I found a problem with the way it determines if it's a class when minified.

So this will use ClassProvider because the class name starts with uppercase:

class Person {
// code...
} 

when minified it will turn it into something along the lines of:

class r {
// code...
}

That will obviously throw errors because it will incorrectly use the FactoryProvider instead

The only way I've managed to make it work has been to write:

var Person = class {
// code...
}

This will obviously not have anything in the name property so it will work because it will not go into the if (clsOrFunction.name) block in the isClass function and check the prototype instead of the name.

I've been trying to think what else could work for determining if it's a class or not, but this seems like a tricky issue...

gah-boh avatar Oct 02 '14 21:10 gah-boh

How about checking the prototype? If it's a Function object, then it's a function. If it's a sub-type of Function, then it's a class (most likely)?

Alxandr avatar Oct 02 '14 21:10 Alxandr

If there is no name property it checks the prototype.length in the isClass function. The main problem I see is that it checks the name property first

I'm not sure what you mean by sub-type of function. Don't want to assume anything, can you clarify please?

gah-boh avatar Oct 02 '14 21:10 gah-boh

Oh, wait. I'm completely thinking wrongly about this. My bad.

Alxandr avatar Oct 03 '14 09:10 Alxandr