Constant properties
Bacon also provides us ways to create constant properties. Constant properties are initialized at the time of creation and cannot be reinitialized, that is, new values cannot be pushed.
A constant property is created using the Bacon.constant()
constructer. We need to pass the value of the property to the constructor. A constant property can be merged, concatenated, combined, zipped, sampled, filtered, and transformed.
Here is an example of how to create a constant property. Place this code in the index.js
file:
var script_start_time = Bacon.constant(Date.now()).map(function(value){ var date = new Date(value); return (date).getHours() + ":" + (date).getMinutes() + ":" + (date).getSeconds(); }); script_start_time.onValue(function(value){ console.log("This script started running at : " + value); })
Here, the constant
property stores the time at which the script was started and prints the time.