Start a new topic

Incorrect method overloading in JS when inheriting class has same method as base


Snippet

public class A<T>
{
 public virtual void Save(T str)
 {
    console.log("Test - ", str);
 }
}
 
public class B : A<string>
{
 public void Save()
 {
    base.Save("this is B");
 }
}
 
public static class C
{
 public static void Run()
 {
 new B().Save(); //Outputs "this is B" correctly, as expected
 
 // Now run "new B().Save();" in browser, and you'll get "Test - [undefined]"
 // Looks like the 'new' method does not receive the correct overload in JS (it gets 'Save$1()')
 // I'd expect it to be 'Save()' by default
 }
}

Also, 'new' keyword does not help here...


OK, if i put

[Js(RuntimeDispatch = 0)]

on the B.Save method, it solves it - de-facto.

Yet, i'd expect it to behave like that without me guessing around which method should i decorate with 'RuntimeDispatch'..

You must decorate all methods in the same group with Js[(RuntimeDispatch=X)], they all will have the same name in JS.

Login or Signup to post a comment