Knockout: Object Output Concept

by andypotanin

HTML

<div data-bind="text: $data.name"></div>
<div data-bind="text: $data.time"></div>

JavaScript

console.clear();

var Sock = function ( name ) {
    this.name = name;
}

Object.defineProperties( Sock.prototype, {
    'set': {
        'value': function (key, value) {
        
            if (ko.isObservable(this[key])) {
                this[key](value);
            } else {
                this[key] = value;
            }
        
        }
    },
    'ViewModel': {
        'get': function() {

            console.log( 'this', this.name );

            return new (function() {

             console.log( 'this.name', this );

             this.name = ko.observable( this.name );
             this.time = ko.observable( 'asdf' );
                
             //this.time = ko.observable(this.time);

                
            });

        }
        
    }
});

var MySock = new Sock( 'DirtySock' );

ko.applyBindings( MySock.ViewModel );

// setInterval(function () { MySock.set('time', new Date().getTime()); }, 2000);