I want to know if it is possible to declare an array in Javascript of the type "com.peregrine.servicecenter.PWS.Common.MessageType". In java it is easy but in javascript I have not idea. Thanks.
-
Check out this thread; it basically asks the same question: stackoverflow.com/questions/881515/…Jeff– Jeff2011-06-21 01:48:48 +00:00Commented Jun 21, 2011 at 1:48
-
Is your question really "How do I declare something in JavaScript that is an instance of a particular Java class?" You do understand that Java and JavaScript are separate languages?nnnnnn– nnnnnn2011-06-21 02:28:41 +00:00Commented Jun 21, 2011 at 2:28
-
I've never worked with namespaces but I'm going to read about it, thanks.user807623– user8076232011-06-21 14:31:29 +00:00Commented Jun 21, 2011 at 14:31
-
Yes, I know they are separate but the question is about if you can "simulate" a java class array in Javascript. Thanksuser807623– user8076232011-06-21 14:44:40 +00:00Commented Jun 21, 2011 at 14:44
-
@nnnnnn Java is to JavaScript as Car is to Carpet. :-) (I know you know the difference user, but I couldn't help it)cwallenpoole– cwallenpoole2011-06-21 14:48:33 +00:00Commented Jun 21, 2011 at 14:48
|
Show 2 more comments
4 Answers
No, it is not possible. The Array in JS doesn't care what you've put in it, or even that the array indexes are numeric. Java, on the other hand, requires strict typing of both. I'd even go so far as to say that even Object[] is a completely different paradigm from [].
1 Comment
user807623
Bad news to me. Thank you for your answer.
You can declare the array in such a way.
var arr = [];
it can contain object or array of object by calling
arr.push(x)
Reference
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array
1 Comment
user807623
I tried that before but it still is a non type array. Thank you anyway.