michael@0: // optimized michael@0: (function(b) { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })({a:'A', b:'B' }); michael@0: (function() { michael@0: var b = {a:'A', b:'B' }; michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })(); michael@0: (function() { michael@0: let (b = {a:'A', b:'B' }) { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: } michael@0: })(); michael@0: (function() { michael@0: var b = {a:'A', b:'B' }; michael@0: (function () { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })(); michael@0: })(); michael@0: (function() { michael@0: let (b = {a:'A', b:'B' }) { michael@0: (function () { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })(); michael@0: } michael@0: })(); michael@0: (function() { michael@0: var b = {a:'A', b:'B' }; michael@0: (function () { michael@0: (function () { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })(); michael@0: })(); michael@0: })(); michael@0: michael@0: // not optimized: michael@0: (function() { michael@0: var b = {a:'A', b:'B' }; michael@0: with ({}) { michael@0: (function () { michael@0: assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); michael@0: })(); michael@0: } michael@0: })(); michael@0: (function() { michael@0: var b = {a:'A', b:'B' }; michael@0: var bad = function() { b = {a:1, b:2}; return 'X' } michael@0: Object.defineProperty(b, 'x', {get:bad}); michael@0: assertEq("xabc".replace(/x|a|b/g, function(a) { return b[a] }), 'X12c'); michael@0: })();