Discord
Login
Community
DARK THEME

Inheritance doesn't work in JavaScript code linked to MicroScript.

https://microstudio.io/i/Loginus/class_race/

Inheritance doesn't work in JavaScript code linked to MicroScript.

I can't make classes that inherit from each other work. I always get an error.

If I simplify the classes so that they have no methods

// file b_js
global.B = class extends global.A{}
// file c_js
global.C = class extends global.B{}
// file d_js
global.D = class extend global.C{}

then the code runs, but once every few program restarts something like "race condition" occurs and there is an error message.

Earlier, someone in the explore section demonstrated a similar effect, only for the entire code written in JavaScript.

https://microstudio.dev/i/Desean/jsclassissues/

You should check this answer: https://microstudio.dev/community/questions/javascript-how-to-reference-objects-from-other-files/280/2/

This doesn't work for a combination of JavaScript and MicroScript code.

Check the code >> https://microstudio.io/i/Loginus/class_race_2/

I think there is a problem with the way you define the print method in your classes. Should be more like:

  print() {
    global.print(...)
  }

The problem is inheritance.

See the Ctrl-Shift-I logs.

Here's the code that doesn't work - but if you comment out the line containing super() in the test method of class C - it will work.

https://microstudio.io/i/Loginus/class_race_3/

While creating the project (MicroScript + JavaScript), I encountered an error where the classes do not see each other and the code does not run properly. So since I didn't have any feedback about the error, I started changing the definition of the z methods

name() { ... }

on

name = function(){ ... }

Same with classes, class name{.....}

on

name = class{ .... }

and later on

global.name = class extends global.innerName{ .... }

which made the classes start inheriting correctly.

It works but has limitations.

When I create two directories .

One file with one class in each directory.

sub_1 a_js

sub_2 c.js

It is not possible to run a class from the c_js file (the class from this file inherits from the class from the a_js file). If I drag the c_js file to the sub_1 directory, the project works.

@Loginus sorry I wasn't able to answer earlier ;

As said there are problems with your example class_race_2, in how you declare the print method.

See the fixed (and working) example here:

https://microstudio.dev/i/microstudio/class_race_2/

My mistake . I'm totally stupid.

I thought that in JavaScript "super" works the same way as in MicroScript and during code execution it will be solved without the need to indicate which exactly method I want to call.

@Loginus don't blame yourself too much! It happens to all of us :-) Actually I had to search and find again how this works in JavaScript. It is different in CoffeeScript by the way ; in JavaScript, super.print() ; in CoffeeScript or microScript, you just call super() (within the print method).

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community