Advertisement
Guest User

Untitled

a guest
May 27th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1.  
  2. function loadData(url,onResponse){
  3. var xhr = new XMLHttpRequest();
  4. xhr.open("GET", url);
  5. xhr.onreadystatechange = function(){
  6. if(xhr.readyState === 4 && xhr.status === 200){
  7. var infoObj = JSON.parse(xhr.responseText);
  8. onResponse(infoObj);
  9. }
  10. }
  11. xhr.send();
  12. }
  13.  
  14. function useRetrievedData(dataObj){
  15. var conversion = new CurrencyConv(dataObj, "NOK", "SEK");
  16. }
  17.  
  18. function someshit(){
  19. loadData("http://example.com/currencies", useRetrievedData);
  20.  
  21. }
  22.  
  23.  
  24.  
  25. function CurrencyConv(data,from,to){
  26. this.from = from;
  27. this.to = to;
  28. this.rate = data[from][to];
  29.  
  30. this.offlineUpdate = function(newTo){
  31. this.to = newTo;
  32. this.rate = data[this.from][this.to];
  33. };
  34. this.onlineUpdate = function(newTo){
  35. var self = this;
  36. loadData("http://example.com/currencies", function(dataObj){
  37. self.to = newTo;
  38. self.rate = dataObj[self.from][self.to];
  39. });
  40. };
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement