2

I have an instance remote from a factory in a vendor script and I need to extend that instance with my own methods and members.

I found the following useful answer Extending this in Typescript class by Object.assign suggesting

BaseRemote.prototype = remote;

It seemed a clean solution at first but, I suspect due to strict mode, I'm getting the following error:

TypeError: Cannot assign to read only property 'prototype' of function 'class BaseRemote { }'

How can I extend an instance / change its prototype like that without disabling strict mode?

2
  • 1
    try Object.setPrototypeOf() Commented Nov 12, 2020 at 12:29
  • 1
    @captain-yossarian thanks captain it's working superb, please kindly post a short answer, best containing a link to MDN Commented Nov 12, 2020 at 18:39

1 Answer 1

1

Try next example :

Object.setPrototypeOf(obj, prototype)

Please see the docs

UPDATE I think it worth looking on this answer also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.