I know that if you create an object in JS, you can do it like this:

var obj = { toString: function () { return "мой обьект" } }; 

Wherein:

 alert(obj); // Выводит "мой обьект" 

The question is how after the function is declared, so that calling it without () returns not the function code, but what you need ie:

 function myFunc(){ // Здесь секретный код } 

How to make alert(myFunc); did not output the function myFunc(){//Здесь секретный код} , but what I want, for example, the line "My secret function"?

  • alert (myFunc ()); -- not that? - Anton Mukhin
  • NOT THAT! I wrote it is necessary toString and not return, you will first learn JavaScript and then minus! - Rules

1 answer 1

 function myFunc(){ myFunc.toString = function(){ return "Моя секретная функция"; } }; myFunc(); alert(myFunc); 
  • Thank you, I tried to use this and just realized that it changes depending on the call and I had to use the name of the function - Rules