Lodash.js – once() function
A simple Lodash.js example of the once() function, which invokes a function only once. If you try to invoke it more times you will get only the first result.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen example"/>
<title>Tizen lodash.js example</title>
<script src="js/lodash.min.js"></script>
</head>
<body>
<div id="first">
</div>
<br>
<div id="second">
</div>
<script>
var firstDiv = document.getElementById('first');
var secondDiv = document.getElementById('second');
var firstValue = function() {
secondDiv.innerHTML += "START THE APP!!!<br>";
}
firstDiv.innerHTML = "Having a function which will be run only once by the lodash once functionality:<br><br>";
firstDiv.innerHTML += firstValue;
var fireUp = _.once(firstValue);
fireUp();
fireUp();
fireUp();
fireUp();
</script>
</body>
</html>