javascript - observable properties

observable properties

by Željko Szep

JavaScript

function Book(name, price) {
    this.name = function (val) {};

    this.price = function (val) {};

    this.onPriceChanging = function (callback) {};

    this.onPriceChanged = function (callback) {};
}

var book = new Book("Javascript the Good Parts", 5.99);
console.log("The name of the book is " + book.name());
console.log("The price of the book is " + book.price());

book.onPriceChanging(function (b, price) {
    if (price > 100) {
        console.log("Error, the price is too high");
        return false;
    }
    return true;
});