2

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.

7
  • Check out this thread; it basically asks the same question: stackoverflow.com/questions/881515/… Commented 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? Commented Jun 21, 2011 at 2:28
  • I've never worked with namespaces but I'm going to read about it, thanks. Commented 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. Thanks Commented 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) Commented Jun 21, 2011 at 14:48

4 Answers 4

2

sure it's possible:

var myArray = [];

remember that javascript is not a statically typed language, so you don't need to declare an array of a specific type.... just an array. Now, given the type you're referring to, I don't think that's exactly what you're asking though...

Sign up to request clarification or add additional context in comments.

Comments

0

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

Bad news to me. Thank you for your answer.
0

You cannot declare an array to exclusively consist of a particular type. However, you can declare an array (var myArray = [];) and you can add objects of your intended type to it (myArray.push(myMessageType);).

Comments

0

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

Array functions in jQuery

1 Comment

I tried that before but it still is a non type array. Thank you anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.