Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:11:38+00:00 2026-05-28T04:11:38+00:00

In a page I create an instance of a class (MyClass) , this class

  • 0

In a page I create an instance of a class (MyClass), this class has 2 methods. But I’d like to do 2 things :

  1. In (1), set the value this.message
  2. In (2), call the information method or another method of the class

Thank,

<script type="text/javascript">
    $(document).ready(function () {
        var myClass = new MyClass("MyParam");
        $('#Target').click(function (event) {
            myClass.save("Test");
        });
    }); 
</script>

function MyClass(myParam) {
    this.myParam = myParam;
    this.isError = false;
    this.message = "";
}

// Define the class methods.
MyClass.prototype = {
    save: function (action) {
        **(2)**
    },
    information: function (action) {
        **(1)**
    }
};

Update1

When I execute the code below the data value in information is show as undifined

MyClass.prototype = {

    click: function (action) {
        var myData;
        $.post(....., $("form").serialize(),
            function (data) {
                myData = data;
            });

        this.isError = this.information(myData);
    },

    information: function (data) {
        alert(data);
        return true;
    }

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:11:39+00:00Added an answer on May 28, 2026 at 4:11 am

    Inside the save and information functions, this should be the current MyClass object.

    So, inside save, this.message should work, and inside information, this.save() should work.

    UPDATE:

    click: function (action) {
        var myData;
        $.post(....., $("form").serialize(),
            function (data) {
                myData = data;
            });
    
        this.isError = this.information(myData);
    }
    

    $.post is an AJAX request and is ran asynchronously. Meaning that this.isError = this.information(myData); is ran before it finishes, therefore myData is undefined. You need to call this.information from inside the callback.

    Inside the callback, this will no longer be your MyClass object, so we need to save a reference to it. Like this:

    click: function (action) {
        var that = this;
        $.post(....., $("form").serialize(),
            function (data) {
                that.isError = that.information(data);
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On page one I would like to create an instance of a class as
I have my views render to route requests like /controller/action (for instance, /Page/Create), so
I have set permission to allow anonymous user to create page. but when the
I have a class Page that creates an instance of DB , which is
I have a class that looks like this: class SearchService include Mongoid::Document key :name,
I have a class which inherits from the System.Web.UI.Page class, like mysystem . When
I'm using my code-behind page to create a save button programmatically: Button btnSave =
In my asp.net mvc page I create a link that renders as followed: http://localhost:3035/Formula/OverView?colorId=349405&paintCode=744&name=BRILLANT%20SILVER&formulaId=570230
In my simple starter asp page I create a DataTable and populate it with
I'm trying to create a page where a user selects the type of subscription

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.