di.js
di.js copied to clipboard
isClass and minification
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...
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)?
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?
Oh, wait. I'm completely thinking wrongly about this. My bad.