Floppy,
@Floppy@mastodon.me.uk avatar

experts, I need advice. I'm trying to extend a class in order to override a method or two. It defines everything in its constructor, and I can't work out how to use anything in the original class from my new one.

Could anyone suggest to me how syntactically I should minimally replace onKeyDown and handleKeyDown with my own versions, while still being able to use functions and properties from the base class? I'd really appreciate the guidance!

Code: https://github.com/mrdoob/three.js/blob/885c2dbab575e6528464e096784680d19914c3f3/examples/jsm/controls/OrbitControls.js

Krazov,
@Krazov@mstdn.social avatar

@Floppy, Github is not easily readable on the phone, so it's a bit of a random idea, but wasn't it possible to run super.someMethod()? So you can call a method from what you're extending.

Floppy,
@Floppy@mastodon.me.uk avatar

@Krazov no, all the scopes were screwed up. Think I've got a solution now though!

almostobsolete,
@almostobsolete@mastodon.me.uk avatar

@Floppy Doesn't look like there's a good way to overide onKeyDown while still using the original code. It's all hidden inside the closure. I think you might be stuck without modifying the library or copy pasting a bunch of code out of it. It's unfortunate that's how the library is written!

Of course depending on what you need to do you might just be able to add a capturing event handler to the containing element. Then you can decide whether to let the event propogate down or not.

Floppy,
@Floppy@mastodon.me.uk avatar

@almostobsolete thanks! I could override the event handling completely, but I still want to call stuff inside the original class to control the camera; I guess that’s not possible with it all wrapped up like that.

Floppy,
@Floppy@mastodon.me.uk avatar

@almostobsolete looks like I’ll have to just copy it wholesale.

almostobsolete,
@almostobsolete@mastodon.me.uk avatar

@Floppy yeah unfortunately I think that’s the only option for those bits not exposed on the the this object

  • All
  • Subscribed
  • Moderated
  • Favorites
  • javascript
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • cubers
  • GTA5RPClips
  • cisconetworking
  • ethstaker
  • osvaldo12
  • modclub
  • normalnudes
  • provamag3
  • tester
  • anitta
  • Leos
  • megavids
  • lostlight
  • All magazines