Q:

Are there compatibility issues when using this.constructor from with a constructor invocation to access static properties?

I'd like to use a constructor's static properties during initialization as such:
var MyConstructor = function() {
  this.foo = 'foo';
  this.set_bar();
}

MyConstructor.bar = "bar";

MyConstructor.prototype = {
  set_bar: function() {
    this.bar = this.constructor.bar;
  }
}

var myObj = new MyConstructor();

This seems to work just fine in new browsers, but does it fail in old browsers? I've been having trouble finding this out on Google. I'm wondering whether some browsers set this.constructor after construction, such that the property is not available during construction.

A:

There is no setting properties, they are looked up on the object. If the property isn't on the object, it's looked up on the object's prototype object. If it's not on the object's prototype object, it's looked up on the object's prototype object's prototype object and so on.
Your code does not work as expected because MyConstructor.prototype = overwrites the default prototype object which has the proper constructor. So MyConstructor.prototype does not have a constructor property and neither does myObj. So this.constructor === Object, not MyConstructor. Object.bar is undefined, and so is myObj.bar as a consequence.
The fix is either extending the default prototype instead of overwriting, or reinserting the constructor:
MyConstructor.prototype = {
    set_bar: function() {
        this.bar = this.constructor.bar;
    },

    constructor: MyConstructor
}

