Default value for function parameter?

后端 未结 4 1917
情深已故
情深已故 2020-12-16 01:17

So I\'ve been doing this for as long as I can remember, but I\'m curious if this is really what I should be doing. You write a function that takes a parameter, so you antic

4条回答
  •  失恋的感觉
    2020-12-16 02:03

    Hopefully this answers a bit clearer for someone - I ended up using the ol' check for undefined if(typeof functionparameter !== 'undefined') as per:

    $.fn.extend({
        doThing: function(stringparameter = 'FooBar!', functionparameter){
            console.log('Here is your string '+stringparameter);
            // Run it if it's been passed through:
            if(typeof functionparameter !== 'undefined') functionparameter();
    });
    

提交回复
热议问题