Observer pattern in Javascript

Observer pattern is common. Objects can subscribe and get notifications about other objects' changes. It's the base for MVVM, bindings and everything that can be considered as "reactive".
How it can be implemented in Javascript?
We can check how Knockout framework works: = ko.observable(1);  
//then read
var propertyValue =;  
//and write;  

After creating a ko.observable object you can subscribe to its notification: {  
    alert("Property value changed to: " + newValue);

The problem with such an implementation is you can easily forget about "()" and overwrite the property with a value: = 5454;  

Boom. You can say goodnight to your observable property. Is there a way to allow to use simple assignment and read like a standard field, and use observator pattern same time?
With ES5, it is! Object.defineProperty allows us to define a property, and getters/setters on it. So, we can create a module, that allows us to easily add a property, and maintains the subscribers list. Full code below.

var Observable = (function(){  
    var subscribers = {};
    var subscribe = function(obj, subscriber, subscriberCallback){ 
        subscribers[obj] = subscribers[obj] || [];
        subscribers[obj].push({subscriber: subscriber, callback: subscriberCallback});

    var unsubscribe = function(obj, subscriber){
      subscribers[obj] = subscribers[obj] || [];
      var pos = -1;
      for(var i=0; i<subscribers[obj].length; i++)
        if(subscribers[obj][i].subscriber === subscriber)
          pos = i;
        subscribers[obj].splice(pos, 1);

    var addObservableProperty = function(obj, property){
        var onPropertyChanged = function(property, bValue, newValue){
            for(var i = 0; i < subscribers[obj].length; i++)
                var subscriber = subscribers[obj][i];
      , obj, property, bValue, newValue);
        var propField = undefined;

        Object.defineProperty(obj, property, {
          get: function() {
            return propField; 
          set: function(newValue) { 
            if(propField !== newValue){
                propField = newValue; 
                onPropertyChanged(property, propField, newValue);
          configurable: true
    return {
      subscribe : subscribe,
      unsubscribe : unsubscribe,
      addObservableProperty : addObservableProperty

Subscribers are grouped in subscribers by notifying object. When a property changes, onPropertyChanged is called and finds appropriate callbacks.
We can create a model with observable properties, and subscribe for notifications:

var Model = function(){  
    Observable.addObservableProperty(this, "testProp");

var Observer = function(name){ = name;
    this.observerCallback = function(obj, prop, oldValue, newValue){
       log("->Callback[""]: "+ JSON.stringify(obj) + "  " + prop +"  "+ oldValue +"  "+ newValue);

var model = new Model();  
var observer = new Observer("observer");  
Observable.subscribe(model, observer, observer.observerCallback);  
//and unsubcribe
Observable.unsubscribe(model, observer);  

Properties cannot be accidently overwritten, and thanks to excessive use of closures, this solution is pretty hermetic! No additional methods on observable objects and so on. Probably some additional cases should be taken into consideration in production (like - null object as observer, how to unsubscribe it etc. - maybe some guid mechanism), but it still seems to be pretty usable.

Full source code with a working sample is available on JsFiddle here;

BTW in modern browsers there are functions like Object.observe and Array.observe, but their compatibility IMO is still in "not a real world usage" phase.