Security: Passing a function as a parameter in JavaScript -


i very new javascript, please bear me!.

i wondering if pass function parameter function in javascript, example (disclaimer: code may not 100% correct, should idea!):

function(param1, param2) {     ....    // param 1    param1 += 10;    ....     // param 2 function, call    param2();     ..... } 

is potential security risk, or common way of programming in javascript?.

thanks.

in javascript, functions first class citizens. can assign function var, pass functions arguments other functions or return function result function.

there many methods in javascript accept function argument(also called callback functions). 1 such example foreach

array.prototype.foreach();  var elements = [42, 33, 45, 5];  elements.foreach(/*anonymous function*/function(element, index) { // element });  elements.foreach(callback);  function callback(element, index) { //do element } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -