admin管理员组

文章数量:1026073

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in .html, it works just fine...

what does it do wrong?

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in http://esprima/demo/validate.html, it works just fine...

what does it do wrong?

Share Improve this question asked Dec 2, 2015 at 22:59 pillarOfLightpillarOfLight 9,01216 gold badges61 silver badges91 bronze badges 3
  • I just run in Google Chrome's console and Firefox console and it's works. – caballerog Commented Dec 2, 2015 at 23:18
  • In Firefox its apparently different – frontend_dev Commented Dec 2, 2015 at 23:21
  • chrome silently ignores it but on firefox it still will make the network request as @frontend_dev mentioned – enjoylife Commented Dec 2, 2015 at 23:23
Add a ment  | 

1 Answer 1

Reset to default 4

I think this line is problematic:

"src": '',

So you have in essence a blank src. The error itself indicates that you get some HTML in response, in this case apparently the browser just tries to load the page you are currently on (watch the network panel). But try to use something more meaningful with your src, or leave it out pletely if you just want to create a script tag.

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in .html, it works just fine...

what does it do wrong?

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in http://esprima/demo/validate.html, it works just fine...

what does it do wrong?

Share Improve this question asked Dec 2, 2015 at 22:59 pillarOfLightpillarOfLight 9,01216 gold badges61 silver badges91 bronze badges 3
  • I just run in Google Chrome's console and Firefox console and it's works. – caballerog Commented Dec 2, 2015 at 23:18
  • In Firefox its apparently different – frontend_dev Commented Dec 2, 2015 at 23:21
  • chrome silently ignores it but on firefox it still will make the network request as @frontend_dev mentioned – enjoylife Commented Dec 2, 2015 at 23:23
Add a ment  | 

1 Answer 1

Reset to default 4

I think this line is problematic:

"src": '',

So you have in essence a blank src. The error itself indicates that you get some HTML in response, in this case apparently the browser just tries to load the page you are currently on (watch the network panel). But try to use something more meaningful with your src, or leave it out pletely if you just want to create a script tag.

本文标签: firefoxjavascript syntax error expected expressiongot 39lt39Stack Overflow