Bondsmith
Bondsmith

Reputation: 1578

Replacing part of code with variable

How can I replace a ClassName in the code below, with a variable.

I have:

(function (root, factory) {

  factory((root.ClassName= {})); 

  dragged =[].slice.call(_document.getElementsByClassName('ClassName'));

 });

How can I replace where i have the ClassNames with a variable like this:

 (function (root, factory) {

   var x = ClassName

   factory((root.ClassName= {})); 

   dragged =[].slice.call(_document.getElementsByClassName('ClassName'));

 });

Note that it is only a part of the code I have, I do not need to change the code, I just need to call a variable where those classnames are appearing.

Upvotes: 5

Views: 91

Answers (1)

Hamms
Hamms

Reputation: 5107

Are you perhaps looking for something like this?

function (root, factory) {
  var x = "ClassName";
  factory((root[x]= {}));
  dragged = [].slice.call(_document.getElementsByClassName(x));
};

Upvotes: 4

Related Questions