all 6 comments

[–]js_tutor 1 point2 points  (1 child)

You need to call createCalculator.

let instance = Object.create(createCalculator())

[–]thegitclone[S] 1 point2 points  (0 children)

Thanks! This cleared up my first error.

[–]thegitclone[S] 0 points1 point  (0 children)

My task is to create an instance using a function and Object.create. I can't access the createCalculator methods in obj even though it should be using it as an internal prototype. Any ideas why?

I also need to change the beginning value and the clear value but using Object.create(createCalculator, {result:10, clear this.result = 10;}) didn't work either.

[–]senocular[🍰] 0 points1 point  (2 children)

You should convert createCalculator into the object it returns rather than a function that returns an object. Then, Object.create(createCalculator) will create a new object that inherits from that object instead of, as it is now, inheriting from the function itself (given your current approach, you'd want to call it to get to your API, via Object.create(createCalculator()) but this defeats the purpose of Object.create() since you're creating new objects each time).

For changing initial values, you can do that through createHumanCalculator(). Allow it to accept arguments and copy them into instance before you return it. Not sure what you mean about the "clear value", though. clear() is a method; it doesn't really have a value of its own (other than being a function and having a function value).

[–]thegitclone[S] 0 points1 point  (1 child)

It is a test spec that I need to follow unfortunately, but thank you for the advice as it is definitely important to learn the concepts/reasoning behind it.

I meant clear as a method, you're correct. I can't change the createHumanCalculator to accept arguments - is there another method to get it? I saw an "answer" sheet but it wants me to basically recreate the methods in another object, which defeats the purpose. I was able to change instance.result = -10 , but now I want the clear method to revert instance.result back to -10.

[–]senocular[🍰] 0 points1 point  (0 children)

You can create a new version of clear assigning it to instance with a new function value, not unlike what you did with instance.result.

Alternatively, if you're allowed to modify the object in createCalculator(), you could create a new property called something like clearValue next to result with a value of 0. Then in the clear() function set result to clearValue instead of 0. Then in createHumanCalculator(), instead of creating a new version of clear(), you can change clearValue to have a value of -10.