JSFiddle - React, Tailwind, and code Playground

by texinwien

JavaScript

_.mixin({
  getLazy : function (obj, property, lambda) {
		obj.__defineGetter__(property, function () {
			var memo = lambda.apply(obj);
			this.__defineGetter__(property, function () {
				return memo;
			});
			return memo;
		});
	}
});

var someObj = function () {
	_.getLazy(this, 'firstTime', function () { return new Date().getTime()});
}

console.log('before initialization: ' + new Date().getTime());
var myObj = new someObj();
console.log('before first call: ' + new Date().getTime());
setTimeout( function () {
    console.log('first call: ' + myObj.firstTime);
    console.log('after first call: ' + new Date().getTime());

    setTimeout( function () {
        console.log('last call: ' + myObj.firstTime);
        console.log('after last call: ' + new Date().getTime());
    }, 99);
}, 99);