Jump to content

OOP, simple question.


xenophobia

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/116809-oop-simple-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.