Hello. Tell me what it is called ?:

var val1 = 'первое значение', val2 = 'второе значение'; str.myFunc(val1, val2); 

Where functions are called as stated above, and not myFunc(val1, val2) Something resembling the writing of plug-ins for jQuery, I mean it:

 $.fn.myFunc = function(val1, val2) { // параметры плагина } 

But to get called wrong, $(el).myFunc('первый параметр', { '': ... }); and so, 'какое-то значение'.myFunc(val1, val2);

Closed due to the fact that the essence of the question is not clear to the participants of the Grundy , lexxl , cheops , Kromster , user194374 Aug 10 '16 at 6:01 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    This is called a variable number of parameters. If the announcement is one case, if the call is the case 2 - nick_n_a
  • one
    @VladimirGamalian nick_n_a I think the vehicle is talking about Method Chaining ..... in Russian there is a "chain" ..... which is applied to the object - Alexey Shimansky
  • one
    Or is meant to add a named function to a variable? - nick_n_a pm
  • one
    It is worth giving a complete example, and not some value . - Grundy
  • 2
    @ Alexey Shimansky, the prototype expansion is more likely - Grundy

2 answers 2

This is called Extending JavaScript Native Objects . It is not recommended to do this extremely - as it may cause a conflict in JS libraries / frameworks, which will lead to a long debugging - why their stated functionality does not work or is buggy.

  • one
    try to link to a specific source, links to search engines are not welcome - Grundy
  • 2
    @Grundy ok - changed the link to a good article. - Goncharov Alexander

You can add a new function to the prototype of the object of the type you are working with.

Example:

 String.prototype.console = function(){console.log(this);} "str".console() 

But it is better (because standard logic can be broken) to create an object of its own type and implement the necessary functionality for it.