How to get value from Object, with default value

前端 未结 4 811
梦毁少年i
梦毁少年i 2021-02-01 00:13

I constantly find myself passing config values to functions accessing them like this:

var arg1 = \'test1\';
if(isUndefined(config.args.arg1)){
  arg1 = config.ar         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 00:45

    try var options = extend(defaults, userOptions);

    This way you get all the userOptions and fall back to defaults when they don't pass any options.

    Note use any extend implementation you want.

提交回复
热议问题