473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Class.forName

2
Hi,

is there something in javascript like Class.forName in Java? I have the name of my Objectname as String so I can't use the keyword new!

Thanks,
shed
Jul 24 '07 #1
4 4816
iam_clint
1,208 Expert 1GB
depends whats class.forname do?
Jul 24 '07 #2
pbmods
5,821 Expert 4TB
Heya, shed. Welcome to TSDN!

Are you trying to get the name of the class, given an instance of that class?
Jul 24 '07 #3
shed
2
Hi,

I have the name of the class as a String e.g. "myClass". Now I want to create a new Instance. In Java I'll get a Class Object when calling Class.forName("myClass") and then I'm able to create a new Instance with "new".
How can I do this in JS?+
Jul 25 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

have a look at the following example that implements a method you want ;)

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3. function ABC() { 
  4.     alert('test');
  5. }; 
  6.  
  7. function class_for_name(name) {
  8.     return new Function('return new ' + name)();
  9. }
  10.  
  11. var a = class_for_name('ABC');
  12.  
  13. alert(a.constructor.name);
  14.  
  15. </script>
  16.  
kind regards
Jul 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the...
2
by: Vijay Singh | last post by:
How do you instantiat a class with a Class.forName( ) method, if the class's default constructor requires a parameter?
4
by: Gavin Andrews | last post by:
I use log4j for logging and tend to include the following snipet in all my classes... public class MyClass { // Logging Declarations private static String _className; private static Category...
1
by: Mandar | last post by:
How do i instantiate a class if I get the name of the class at runtime ? I am looking for something like class.forname("classABC") in Java . TIA Mandar
4
by: vasavimaruthi | last post by:
hi, i got class not found exception of a small jdbc program in windows. the program is like this import java.sql.*; public class Db1 { public static void main(String a)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.