Code: Select all
var obj._style.capture();Cheers,
Darkzaelus
Moderator: General Moderators
Code: Select all
var obj._style.capture();Code: Select all
/* ------------ Initial code ----------- */
var div = document.getElementById('sample');
div.my_object = {
sample_func: function () {
alert(this);
//this refers to my_object, which is not what we want
}
};
div.my_object.sample_func();
/* ------------ Sample #1 ----------- */
div.my_object = {
sample_func: function () {
alert(this);
//this now refers to DIV, but you can't access my_object anymore
}
}
div.my_object.sample_func.call(div);
/* ------------ Sample #2 <- correct way how to do it in my opinion ----------- */
div.my_object = {
htmlNode: div, //Reference to DIV
sample_func: function () {
alert(this.htmlNode);
//this.htmlNode refers to DIV
}
};
div.my_object.sample_func();
/* ------------ Sample #3 ----------- */
div.my_object = {
sample_func: function (div) {
alert(div);
//div refers to DIV
}
};
div.my_object.sample_func(div);