Using `this` for Parent Function inside a Nested Function

Viewed 4727

In the Apple "classs", how can the nested function countSeeds() retrieve the value this.price?

jsfiddle: http://jsfiddle.net/VGqEa/

Apple = function() {
    this.price = 17

    this.cutOpen = function() {

        console.log(this.price);
        countSeeds();

        function countSeeds() {
            console.log(this.price);
        }
    }        
}


var apple = new Apple();
apple.cutOpen();

Output

17
undefined
2 Answers
Related