include("Worlds2_Compiled") Person = function(age) { this.age = age; } // ---------------------------------------- Object.prototype.get = function(p) { in callingWorld { return this[p]; } } Object.prototype.set = function(p, v) { in callingWorld { this[p] = v; } } // ---------------------------------------- World.prototype.useForEvaluating = function(f) { var cw = thisWorld; in this { callingWorld = cw; return f(); } } // ---------------------------------------- betterModule = thisWorld.sprout() in betterModule { Person.prototype.makeOlder = function() { this.set("age", this.get("age") + 1); } } // ---------------------------------------- alice = new Person() alice.age = 25 betterModule.useForEvaluating(function() { alex.makeOlder(); }) ourOtherModule = thisWorld.sprout() in ourOtherModule { Person.prototype.makeOlder = function() { this.age = this.age + 1 } } alex = new Person(30) in ourOtherModule { alex.makeOlder() alert(alex.age) } alert(alex.age) // ----------------------------------- Person.prototype.setAge = (function() { var w = thisWorld return function(age) { in w { this.age = age } } })() ourOtherModule = thisWorld.sprout() in ourOtherModule { Person.prototype.makeOlder = function() { this.setAge(this.age + 1) } } in ourOtherModule { alex.makeOlder(); alert(alex.age) } alert(alex.age) // ----------------------------------- // maybe should use more general setter in example above? Object.prototype.set = (function() { var topLevelWorld = thisWorld return function(p, v) { in topLevelWorld { this[p] = v } } })() // ----------------------------------- // the best way to do it Object.prototype.get = function(p) { in callingWorld { return this[p] } } Object.prototype.set = function(p, v) { in callingWorld { this[p] = v } } World.prototype.useForEvaluating = function(f) { var cw = thisWorld in this { callingWorld = cw f() } } in ourOtherModule { Person.prototype.makeOlder = function() { this.set("age", this.get("age") + 1); } } // ---- ourOtherModule.useForEvaluating(function() { alex.makeOlder(); alert(alex.get("age")); }) alert(alex.age); in thisWorld.sprout() { ourOtherModule.useForEvaluating(function() { alex.makeOlder(); alert(alex.get("age")); }) } alert(alex.age)