1 year ago

Can i flexible change function name in javascript?

Posted 1 year ago by kankai

Hi guys,

I'm currently creating my own javascript library, so i started with ajax submit form and i need to make it have flexible result effect. Is there anyway to make function name replace with parameter?

function submitForm(){
  var parameterLength = arguments.length;
  var formID = arguments[0];
  var postUrl = arguments[1];
  var _func = arguments[2];
  $(document).ready(function() {
    $(formID).submit(function (ev) {
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            method: 'POST', // Type of response and matches what we said in the route
            url: postUrl, // This is the url we gave in the route
            data:$(formID).serialize(), // a JSON object to send back
          success: function(response){ // What to do if we succeed
          error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
            console.log("AJAX error: " + textStatus + ' : ' + errorThrown);

function result(_data){


Something like this but i got an error said that _func is not a function. Anyway to make this works?

Please sign in or create an account to participate in this conversation.