Jaxel
Well-known member
Below is my JS...
I believe there are essentially 3 scopes in the above code... the handler/init scope, the click scope, and the ajax scope.
To assign variables from the click scope to the handler scope, I would need to do
However, if I do that, then the values are undefined in the ajax scope and are not accessible based on the values set in the click scope.
In order to get the variables working in the ajax scope, I needed to not define
But if the variables are now global; why can I still access them through
So how do I define variables in the click scope, that I can use in the ajax scope, without having to make them global?
JavaScript:
EWRatendo.RsvpMenu = XF.Element.newHandler(
{
$target: null,
$parent: null,
init: function()
{
this.$target.on('click', '.menu-linkRow', $.proxy(this, 'click'));
},
click: function(e)
{
e.preventDefault();
$target = $(e.currentTarget);
$parent = $(e.currentTarget).parent();
XF.ajax('POST', $target.attr('href'), {}, function (data)
{
alert(this.$target.text);
alert(this.$parent.text);
});
},
});
I believe there are essentially 3 scopes in the above code... the handler/init scope, the click scope, and the ajax scope.
To assign variables from the click scope to the handler scope, I would need to do
this.$target = ....
.However, if I do that, then the values are undefined in the ajax scope and are not accessible based on the values set in the click scope.
In order to get the variables working in the ajax scope, I needed to not define
this
in the click scope; which makes the variables global.But if the variables are now global; why can I still access them through
this
? Global variables aren't preferred anyways...So how do I define variables in the click scope, that I can use in the ajax scope, without having to make them global?