examples/HTML StarterKit/lib/durandal/js/plugins/observable.js
function defineProperty(obj, propertyName, evaluatorOrOptions) {
        var computedOptions = { owner: obj, deferEvaluation: true },
            computed;

        if (typeof evaluatorOrOptions === 'function') {
            computedOptions.read = evaluatorOrOptions;
        } else {
            if ('value' in evaluatorOrOptions) {
                system.error('For defineProperty, you must not specify a "value" for the property. You must provide a "get" function.');
            }

            if (typeof evaluatorOrOptions.get !== 'function') {
                system.error('For defineProperty, the third parameter must be either an evaluator function, or an options object containing a function called "get".');
            }

            computedOptions.read = evaluatorOrOptions.get;
            computedOptions.write = evaluatorOrOptions.set;
        }

        computed = ko.computed(computedOptions);
        obj[propertyName] = computed;

        return convertProperty(obj, propertyName, computed);
    }
function defineProperty(obj, propertyName, evaluatorOrOptions) {
        var computedOptions = { owner: obj, deferEvaluation: true },
            computed;

        if (typeof evaluatorOrOptions === 'function') {
            computedOptions.read = evaluatorOrOptions;
        } else {
            if ('value' in evaluatorOrOptions) {
                system.error('For defineProperty, you must not specify a "value" for the property. You must provide a "get" function.');
            }

            if (typeof evaluatorOrOptions.get !== 'function') {
                system.error('For defineProperty, the third parameter must be either an evaluator function, or an options object containing a function called "get".');
            }

            computedOptions.read = evaluatorOrOptions.get;
            computedOptions.write = evaluatorOrOptions.set;
        }

        computed = ko.computed(computedOptions);
        obj[propertyName] = computed;

        return convertProperty(obj, propertyName, computed);
    }
function defineProperty ( obj , propertyName , evaluatorOrOptions ) { var computedOptions = { owner : obj , deferEvaluation : true } , computed ; if ( typeof evaluatorOrOptions === 'function' ) { computedOptions . read = evaluatorOrOptions ; } else { if ( 'value' in evaluatorOrOptions ) { system . error ( 'For defineProperty, you must not specify a "value" for the property. You must provide a "get" function.' ) ; } if ( typeof evaluatorOrOptions . get !== 'function' ) { system . error ( 'For defineProperty, the third parameter must be either an evaluator function, or an options object containing a function called "get".' ) ; } computedOptions . read = evaluatorOrOptions . get ; computedOptions . write = evaluatorOrOptions . set ; } computed = ko . computed ( computedOptions ) ; obj [ propertyName ] = computed ; return convertProperty ( obj , propertyName , computed ) ; }
Defines a computed property using ES5 getters and setters.
@method defineProperty
@param {object} obj The target object on which to create the property.
@param {string} propertyName The name of the property to define.
@param {function|object} evaluatorOrOptions The Knockout computed function or computed options object.
@return {KnockoutObservable} The underlying computed observable.
Defines a computed property using ES5 getters and setters .