logo
down
shadow

How to pass variable arguments to base class


How to pass variable arguments to base class

By : user2953999
Date : November 21 2020, 07:31 AM
will help you As you've found out, the spread operator is not available yet.
EDIT - Sidenote: Actually, it works now in TypeScript 1.5. Just do super(...args);
code :
class TSBase {
  constructor(...args: any[]) {
    if (this.constructor != TSBase && args.length === 1 && args[0] instanceof Array) {
      args = args[0];
    }

    // work with args here... for example:
    args.forEach((val) => console.log(val));
  }
}

class TSSomeController extends TSBase{
  constructor(...args: any[]){         
    super(args);
  }
}

new TSBase(3, 4);                 // 3, 4
new TSBase([3, 4]);               // Array[2]
new TSSomeController(3, 4);       // 3, 4
new TSSomeController([3, 4]);     // Array[2]
new TSSomeController([3, 4], 5);  // Array[2], 5


Share : facebook icon twitter icon
Pass derived class to function defined to take base class arguments

Pass derived class to function defined to take base class arguments


By : deepika thakur
Date : March 29 2020, 07:55 AM
With these it helps If I have a base class and a derived class, such as: , To answer your two questions:
Python pass arguments of base class

Python pass arguments of base class


By : W.Sariol
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The key word in that error is "positional". You are passing arguments as positional that should be passed as keyword arguments. Change this line:
code :
super().__init__(master, width, height)
super().__init__(master, width=width, height=height)
__init__(self, master=None, cnf={}, **kw)
how to pass arguments to base class constructors in c++

how to pass arguments to base class constructors in c++


By : Damian Funes
Date : March 29 2020, 07:55 AM
it helps some times In your example, you are not passing any values to the obj2 constructor, so your x member remains not initialized.
Remember that obj1 and obj2 do not share any members, they are separate, disconnected instances.
Python inheritance: pass all arguments from base to super class

Python inheritance: pass all arguments from base to super class


By : Sivasaravana Kumar
Date : March 29 2020, 07:55 AM
Hope this helps I am not quite used to class inheritance in Python yet. All I want to do is simply pass all arguments from my base class to the super class when it is created: , Based on your comment, you could do something like this:
How to use `...args` to pass many arguments to base class?

How to use `...args` to pass many arguments to base class?


By : Ryan Woodham
Date : March 29 2020, 07:55 AM
I hope this helps . I am using Typescript 2.0 , The thing is that the complied js is just fine:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org