Edit in JSFiddle

function once(fn, context) { 
	var result;

	return function() { 
		if(fn) {
			result = fn.apply(context || this, arguments);
			fn = null;
		}

		return result;
	};
}

// Test
var canOnlyFireOnce = once(function() {
	console.log('canOnlyFireOnce() fired');
});

canOnlyFireOnce(); // will fire
canOnlyFireOnce(); // won't fire






<html>
<body>
  Check the console. canOnlyFireOnce() should only be logged once.
</body>
</html>
body {
  font-family: arial;
}