javascript - Prepend argument to arguments then apply -


I have a function, message which takes an overview to define the message type And then

  is added to any other argument to create a message for the function message (type) {var msg = _.rest (arguments), purely an undisputed one.  

Add (""); // will actually be used to set a type of div on div / but I'm just using console.log so that it can be as simple as ever. Console.log (type + ":" + msg); }

I want to provide helpful tasks, error , warning , information , which just call With the right type, I am just unsure about the best way to go about this. I can think of two ways but I am not sure I go about it in the right way. Or maybe I want to finish things.

The first path seems a little unnecessary, creating a new array, the first argument and logic are flat.

  Message. Now (this, _. Fleeton (["error", logic]));   

The other way seems a bit ... messed up?

  Array.prototype.unshift.call (logic, "error"); Message.apply (this, arguments);   

Although using my:

  (function () {Array.prototype.unshift.call (logic, 0); console, log (logic) ;}) (1, 2, 3);   

I get the following output:

  [0, 1, 2, 3, undefined, undefined, undefined, ..., undefined]    

  var args = Array.prototype.slice.call (argument); // argin args.unshift ("error") create the actual array; Message.apply (this, args);   

View

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -