Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Stefan Reuther 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: References: 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: Xref: csiph.com de.comp.lang.javascript:5453 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