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 8176301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:07:04+00:00 2026-06-06T23:07:04+00:00

I am developing a JQuery plugin that stores private data in the object’s data

  • 0

I am developing a JQuery plugin that stores private data in the object’s data field (as was recommended in an article I found):

$.fn.awesomify = function (schema, data) {
    $(this).data('schema', schema);
}

I can then retrieve this value in a private method:

function rebuild() {
    var schema = $(this).data('schema');
}

Now the problem I have is that the value of $(this) is different when the method gets called from a different object. For example, the onclick event of an href:

var a = ...;
a.click(function () {
    rebuild(); // Now $(this) is the a-object
});

How should I solve this?

Thanks!

  • 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-06-06T23:07:07+00:00Added an answer on June 6, 2026 at 11:07 pm

    This is because the value of this is determined at invocation time, and is set to the object which the method belongs to, or window if the method is not attached to an object*; rebuild() is not attached to an object, so this is window.

    You can either pass the value of this in as an argument, or use the Function.prototype.call/Function.prototype.apply methods;

    rebuild.call(this);
    

    or:

    rebuild(this);
    
    function rebuild(that) {
        var schema = $(that).data('schema');
    }
    

    * -> Exception is if you’re in strict mode, where its undefined, but this isn’t relevant here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing a site that users the jQuery superfish plugin to construct
I'm developing my first jQuery plugin that offers a number of optional callbacks. For
I am currently developing a rather complex jQuery plugin. One that I am designing
I am developing an application using jquery mobile and flot charts. In That i
I have made a jQuery plugin that works fine when applied to a single
I stumbled upon an issue with event namespacing while developing a jQuery plugin. here
I'm developing a page using the jQuery sparklines plugin. This plugin replaces some CSV
I am developing an autocomplete jquery plugin and I would like to optimise it
I found an anchor plugin for jQuery, and its demo site is at http://www.position-relative.net/creation/anchor/
I am developing a WordPress page that uses a jquery.slideto.js navigation system and html

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.