var myMegaObject = (function(w){ var a, b, c; function log(a){ console.log('log1', a) } return function(b){ this.b = b; this.getb = function(){ log( this.b ); } } })(window); myMegaObject.add = function(){} myMegaObject.prototype = (function(){ var x,y,z; function log(a){ console.log('log2', a) } return { c: 1, getc: function(){ log(this.c) }, event: function(fn){ var c = this.c this.c.onclick = function(){ if(fn.call(c) == false) return false; } } } })(); var myObj = new myMegaObject('asd') myObj.event(function(){ alert(1) });