Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Screen name:
Zoltán Tihanyi
Zoltán Tihanyi's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Ideas
Problems
Expanded view
List view
Private Message
How to create JQuery Class Private Variable
[2Replies]
13-Dec-2013 05:34 AM
Forum:
Using jQuery
Hi all,
I am not a JQuery expert so I am very confused about creating private variable for an object instance.
I want to create a simple jquery plugin, but all instances see the last declared class variables.
Can someone tell me the reason and the solution ?
Sample code :
;
(
function
(
$
) {
/* This is a private declaration, isn't it ? */
var
settings = {
pagesize: 10
}
/* Constructor */
$.fn.myPlugin =
function
(
options
) {
/* Call a private method to save the options */
setVars
(
options
);
}
/* Private method to save the options to a PRIVATE variable */
function
setVars(options)
{
settings = $.extend
( {}
, options
);
}
/* Alert the page size related to the CURRENT instance */
$.fn.myPlugin.refresh =
function
()
{
alert(
settings.pagesize
);
}
} ) (
jQuery
)
;
Calling the plugin :
("
#div1
").myPlugin
( {
pagesize : 11
} )
;
$("
#div2
").myPlugin
( {
pagesize : 45
} );
$("
#div1
").myPlugin.refresh();
$("
#div2
").myPlugin.refresh();
I think the result should be to alert 11 and 45 but only 45 is alerted two times. But why ?
Thank you in advance
Tihi
«Prev
Next »
Moderate user : Zoltán Tihanyi
Forum