My code passes all the tests except the last also, with an IndexOutOfRangeException, which appears to be coming from the Sample Tests.
I too am having this issue. I pass all the test but get a STDERR about the index being out of range despite the numerous testing I did in XCode all came back positive. Not sure if this is a bug or if I am actually doing something wrong.
ahhh my code does not pass it gives me an error after passing all tests. I am a beginner my code may not be very pythonic in nature but to pass this challenge I am sure it is flawless, IndexError out of range is what is being thrown
Very close! In fact your test revealed a small flaw in the spec that I just fixed. If the return value of the constructor is a function, it should return the function — not the result of calling the function.
Hi there. There's a couple things going on here. Let's tackle them one by one.
var instance = Constructor.__proto__;
This line looks up the (special) __proto__ property of the Constructor function. __proto__ is not meant to be used directly by a developer. It's kept around for historical reasons, but the ECMAScript [[proto]] property is meant to be an internal-only property.
Anyway, the __proto__ of Constructor is the Function object, since the Constructor function inherits from Function. So now your var instance is a variable pointing to Function. That's definitely not what you are trying to do, I should say.
As a (big) hint, I would suggest you look up Object.create.
On this line, you are invoking the prototypal bind method of Constructor, which takes as its first parameter a variable to use as this inside of the function. The bind method does not change Constructor or instance — it returns a different function, one which will act like Constructor but use instance as the this keyword. However, you are not capturing that returned function anywhere (e.g. in var something = line), so in essence this line does… nothing. No side effects, no new variables.
var something =
If you want to call Constructor with a particular this value, that is a job for .call or .apply — not .bind. Or you could get a bound function from .bind and immediately call it, but that is not needed.
This is a bit closer to the mark. You are invoking the Constructor and passing in all the additional arguments of nouveau into it as separate parameters — nice use of ES6 spread operator. Unfortunately, inside of Constructor the this keyword is simply the window or global object, if in non-strict mode, or undefined in strict mode; this is because you haven't quite got the binding correct yet, as already explained above. So this function call ends up not quite doing what we need.
A logical last statement, but by now instance isn't what we wanted it to be for reasons explained above.
I hope that helps you get back on track! This one is a little tricky for those still grappling with JS internals, but with a bit more research I think you'll figure it out. Regards,
This comment is hidden because it contains spoiler information about the solution
Much better, greenlit :D
It's a CW problem, the kata has a lot of tests. Report that at CW as a bug: https://www.codewars.com/topics/bug-reports.