Last active
August 29, 2015 14:01
-
-
Save tonekk/700b10d2e284e77e820a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
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