Good day!

Override the return value of the function. Suppose there is:

function getSettings() { return { набор настроек} } 

called in the template for:


In certain circumstances, I need to expand the set of returned settings. Those. I would like to have something like:

 //новая function getSettings() { setting = getSettings(); //получаем старые настройки newsetting = { новые настройки}; $.merge(setting ,newsetting ); return setting; } 

I am not familiar with javascript and jQuery, so here I

  • This is already a recursion ... // new function getSettings () {setting = getSettings (); // get the old settings newsetting = {new settings}; $ .merge (setting, newsetting); return setting; } - AseN

2 answers 2

$ .merge "sticks together" two lists . If the settings are returned as an object , you must use $ .extend !

Option to override the function name:

 var oldGetSettings = getSettings; // без скобок function getSettings() { var value = oldGetSettings(); // other stuff } 

On the other hand, you can simply change the name of the called function in the template:


Or even so, if the new settings are not very many (so as not to disrupt the readability of the code):

 $('#text').editor($.extend(getSettings(), { // ну или $.merge new_setting: 1, another_setting: 2 })); 

If you are writing a plugin, I advise you to do this as follows ( See an example. )

 $.fn.editor = function(options){ options = $.extend({ param_1: 'default_val_1', // дефолтный параметр param_2: 'default_val_2' // дефолтный параметр },options); /* функции плагина и т.д. */ } // подключение плагина с новыми параметрами $('#text').editor({ param_1: 'some_val_1', param_2: 'some_val_2' });