scoping New Yours API Help 459 bytes, JavaScript Soft wrap Raw text Duplicate 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 var test = function ( a ) { this . a = a ; this . out = function () { console . log ( this ); } } var t = test ( 1 ) t . out () // prints out window, since this is bound to window t = new test ( 1 ) t . out () // prints out {a:1, out:function} //or you can return the object explicitly test = function ( a ) { return { a : a , out : function () { console . log ( this ); } } } t = test ( 1 ) t . out () // also outputs {a:1, out: function} Pasted 8 seconds ago — Expires in 365 days URL: http://dpaste.com/2155RTM About dpaste.com ...