xenophobia Posted July 27, 2008 Share Posted July 27, 2008 Let's say I got a class name: "Message" Now I had a function called: send(msg), which received 'msg' parameters as a instance of Message::object. So I will invoke the function like this: var msg_1 = new Message(); msg_1.content = "Hello World!"; send(msg_1); This work fine. So my question is, is there a shortcut, without declare the "msg_1" and directly passed in a object of the class into the parameter, which look something like this: send(new Message(){this.content="hello Word";}); I know it can be done in Java. I also seen some example of this in somewhere I forget in JS. Any idea? Quote Link to comment Share on other sites More sharing options...
corbin Posted July 27, 2008 Share Posted July 27, 2008 You could try: send((new Message()).content="Hello World!"); But I don't think that will work. If the object doesn't have to be a Message, you could always just do: send({"content": "Hello World!"}); Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 27, 2008 Share Posted July 27, 2008 Why not try something like: function Message(content) { this.content = content; } send(new Message("Hello World!")); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.