Javascript programlamaya daha fazla nesne yönelimli bir yaklaşım benimsemeye çalışan birisi olarak, muhtemelen çok temel bir şey olduğunu düşündüğüm tökezleyen bir bloğa rastladım, ancak aşağıdaki nesne uygulamasını al (varsayalım jQuery nesnesi) bu koda mevcuttur:JavaScript Kapsam soru
function Foo()
{
this.someProperty = 5;
}
Foo.prototype.myFunc = function()
{
//do stuff...
};
Foo.prototype.bar = function()
{
//here 'this' refers to the object Foo
console.log(this.someProperty);
$('.some_elements').each(function()
{
//but here, 'this' refers to the current DOM element of the list of elements
//selected by the jQuery selector that jquery's each() function is iterating through
console.log(this);
//so, how can i access the Foo object's properties from here so i can do
//something like this?
this.myFunc();
});
};
Bunun gibi basit bir şey olacağını biliyordum, teşekkürler :-) –