Вопрос о сфере действия JavaScript

Как человек, который пытается применить более объектно-ориентированный подход к моему программированию на javascript, я наткнулся на камень преткновения, который, я уверен, вероятно, является чем-то очень простым, но возьмем следующую реализацию объекта (предположим, что объект jQuery доступен для этого кода):

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();
    });
};
5
задан Bill Dami 8 September 2010 в 17:23
поделиться