/    Sign up×
Community /Pin to ProfileBookmark

Method with Parameter

[code]
<script language=”javascript” type=”text/javascript”>
function call(){
alert(“this is call”);
}
function Obj(){
this.call=call;
this.a;

}
function btn_onclick(){
event.returnValue=false;
var obj1=new Obj();
obj1.call();
}
</script>
<input type=”submit” id=”btn” onclick=”btn_onclick()”/>
[/code]

What I want to do is when I click the button, “this is call” message will appear. I want to do it in a object-oriented way, so I make the “obj” to be my object and the “call()” to be the method inside my “obj” object. The above codes is working after tested, but somehow if I want to pass the parameter to the call method,eg call(messageToBeDisplay), how to I adjust the code that I put above? In short, I simply do not know how to write the method that contains the parameter for the object.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@jack1234authorMay 11.2005 — I think I need to make it simpler..

I want to create a self-defined object called "obj" which contains a method called "call". This "call" method take in a parameter called "messageToBeDisplay". How do I code?
Copy linkTweet thisAlerts:
@code-frogMay 11.2005 — While waiting for an answer to my question I thought this might help with yours.

http://www.webteacher.com/javascript/ch01.html

  • - Good Luck
  • ×

    Success!

    Help @jack1234 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.25,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...