Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
console.clear();
console.log('creating iife');
// assertion function
function assert(condition, msg) {
  if (condition) {
    console.log('Pass');
  } else {
    console.log('Fail: ', msg);
  }
}
var iife1 = (function() {
  function foo() {
    return 'foo';
  }
  
  function bar() {
    return 'bar';
  }
  
  return {
    foo1: foo,
    bar1: bar
  };
})();
// testing
console.log('testing iife object', iife1);
assert(iife1.foo1() === 'foo', 'foo1 function should return string foo');
assert(iife1.foo1() === 'bar', 'foo1 function should return string foo');
assert(iife1.bar1() === 'bar', 'bar1 function should return string bar');
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
d48pro
0viewers