A
A
Arseny Sokolov2016-03-02 17:36:09
RequireJS
Arseny Sokolov, 2016-03-02 17:36:09

How to work with variables in RequireJS?

I was going to implement RequireJS in my project, but there is one gag that I don’t know how to solve correctly using RequireJS.
Now when I load the script on the page, I do it like this:

<script data-name="cabinet" src="/public/js/cabinet.min.js?c={{contract|url_encode}}&k={{apikey|url_encode}}&icq={{icq.uin|url_encode}}&sms={{sms.phone|url_encode}}&email={{email.address|url_encode}}"></script>

And in the script itself I use a function with the help of which I then already get knowledge of the variable:
function getParamByName(name) {
  name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
      results = regex.exec(me_src);
  return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Tell me how to do the same thing but with respect to RequireJS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-03-02
@ArsenBespalov

stackoverflow.com/a/10329014/2327681 ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question