Groups | Search | Server Info | Login | Register


Groups > de.comp.lang.javascript > #5453

Re: Funktion einer Klasse aufrufen als Variablen

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Stefan Reuther <stefan.news@arcor.de>
Newsgroups de.comp.lang.javascript
Subject Re: Funktion einer Klasse aufrufen als Variablen
Date Fri, 3 Nov 2023 18:22:56 +0100
Lines 21
Message-ID <ui3dq1.25o.1@stefan.msgid.phost.de> (permalink)
References <ui2ol9$1j40p$1@gwaiyur.mb-net.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace individual.net spxfepQZCazrirtbp/E7WQEwOjb33kUyTR6O3RWAqK9zmKSpgM
Cancel-Lock sha1:/y2icB4vonNRT1h87LI1wLeoq1w= sha256:T71quBEQP4pOTes1J+KWnXw4dANtt/yOy8A61iUzix0=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 Hamster/2.1.0.1538
In-Reply-To <ui2ol9$1j40p$1@gwaiyur.mb-net.net>
Xref csiph.com de.comp.lang.javascript:5453

Show key headers only | View raw


Am 03.11.2023 um 13:22 schrieb Jan Novak:
>     class MyTest {
>         myTest(data){
>             console.log("innerhalb MyTest.myTest");
>             console.log(data);
>         }
>     }
> 
>     const className = "MyTest";
>     const methodName = "myTest";
>     const myInstance = new window[className]();
> //Ich bekomme hier bereits :Uncaught TypeError: window[className] is not
> a constructor

Was ist denn `window[className]`? Ist deine Klasse überhaupt im
window-Objekt enthalten, oder liegt die nur in einem lokalen Scope?

Die Browserkonsole sagt zumindest: `new window["Array"]()` funktioniert.


  Stefan

Back to de.comp.lang.javascript | Previous | NextPrevious in thread | Find similar


Thread

Funktion einer Klasse aufrufen als Variablen Jan Novak <repcom@gmail.com> - 2023-11-03 13:22 +0100
  Re: Funktion einer Klasse aufrufen als Variablen Jan Novak <repcom@gmail.com> - 2023-11-03 14:29 +0100
  Re: Funktion einer Klasse aufrufen als Variablen Stefan Reuther <stefan.news@arcor.de> - 2023-11-03 18:22 +0100

csiph-web