-6

so I want to rewrite this code from an arrow function to a non arrow function, how will this then be done and what will the code be?

require('isomorphic-fetch');

let items = [];

fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
  .then(res => res.json())
  .then((result) => {
    items = result.items;
    console.log(items);
  }),
  (error) => {
    console.log(error);
  }
hazelbag
  • 1
  • 3
  • As long as you don't use `this` anywhere, you can just replace `{param} =>` with `function({param})` and add the mandatory `{ }` – blex Oct 23 '19 at 21:12
  • please start to assign your require statement on something like "var iso = require(...)" – hatirlatici Oct 23 '19 at 21:14
  • @hatirlatici is it required to have the "require" as a var? In ES6 it is "import" I believe? – hazelbag Oct 23 '19 at 21:16
  • @hazelbag you can chose either require or import. If you use import the format woudl be "import {something} from "somelibrary". If you use require, the format then would be "var something = require('somelibrary"). – hatirlatici Oct 23 '19 at 21:22
  • @hatirlatici ah okay so I will stick to require and thus going forward set it as a var something = require("library"), this makes sense to me, so does import though but learned the require method. – hazelbag Oct 23 '19 at 21:24
  • I find the easiest way to dumb down javascript scripts so Internet Explorer can fail less spectacularly is to use something like babel - it does most of the work for you – Bravo Oct 23 '19 at 21:59

1 Answers1

2
require('isomorphic-fetch');

let items = [];

fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
  .then(function(res) { return res.json(); })
  .then(function (result) {
    items = result.items;
    console.log(items);
  }),
  function (error) {
    console.log(error);
  }
Arik
  • 5,266
  • 1
  • 27
  • 26
  • Thank you much appreciated @Arik. I will give it a try and also play with it and add an async/await function to it. – hazelbag Oct 23 '19 at 21:22