Skip to content

Instantly share code, notes, and snippets.

@tonekk
Last active August 29, 2015 14:01
Show Gist options
  • Save tonekk/700b10d2e284e77e820a to your computer and use it in GitHub Desktop.
Save tonekk/700b10d2e284e77e820a to your computer and use it in GitHub Desktop.
[...]
inputs: {
init: function() {
Array.prototype.forEach.call(kashoderkurs.inputs, function(index, value) {
console.log(index, value);
});
},
// This is how we do it
cash: new (function() {
// Because e.g. private variables here...
var priv = '1337';
// or functions
var privateFunction = function() { console.log('Not callable from outside!');}
this.init = function() {
kashoderkurs.cash.addEventListener('input', this.update());
};
this.update = function() {
var value = kashoderkurs.cash.value;
var rateValue = kashoderkurs.rate.value;
var unitValue = kashoderkurs.unit.value;
if (!parseInt(rateValue)) {
unit.value = 0;
return;
}
var newUnitValue = (value / rateValue).toFixed(2);
if (newUnitValue.match(/.00/)) {
newUnitValue = parseInt(newUnitValue);
}
kashoderkurs.unit.value = newUnitValue;
};
})(),
[...]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment