Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadData(url,onResponse){
- var xhr = new XMLHttpRequest();
- xhr.open("GET", url);
- xhr.onreadystatechange = function(){
- if(xhr.readyState === 4 && xhr.status === 200){
- var infoObj = JSON.parse(xhr.responseText);
- onResponse(infoObj);
- }
- }
- xhr.send();
- }
- function useRetrievedData(dataObj){
- var conversion = new CurrencyConv(dataObj, "NOK", "SEK");
- }
- function someshit(){
- loadData("http://example.com/currencies", useRetrievedData);
- }
- function CurrencyConv(data,from,to){
- this.from = from;
- this.to = to;
- this.rate = data[from][to];
- this.offlineUpdate = function(newTo){
- this.to = newTo;
- this.rate = data[this.from][this.to];
- };
- this.onlineUpdate = function(newTo){
- var self = this;
- loadData("http://example.com/currencies", function(dataObj){
- self.to = newTo;
- self.rate = dataObj[self.from][self.to];
- });
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement