The first type:
function test(a,b){var a = arguments[0] ? arguments[0] : 1;//Set the default value of parameter a to 1var b = arguments[1] ? arguments[1] : 9;//Set the default value of parameter b to 9return a+b;Its equivalent is
function test(){var a = arguments[0] ? arguments[0] : 1;//Set the default value of parameter a to 1var b = arguments[1] ? arguments[1] : 9;//Set the default value of parameter b to 9return a+b;}Call Example
alert(test()); //Output 10alert(test(5)); //Output 14alert(test(5,6)); //Output 11alert(test(null,6)); //Output 7alert(test(6,null)); //Output 15
The second type:
function test(blog,address){blog=blog||'Forget~Simple Thought';address=address||'www.VeVB.COM';alert('The address of the blog name is '+blog+' is '+address);}Its equivalent is
function test(blog,address){if(!blog){blog='Forget~Simple Thought';}if(!address){address='www.VeVB.COM';}alert('The address of the blog name is '+blog+' is '+address);}Call Example
test(); //The blog name is Danwang~The address of Qiansi is www.VeVB.COMtest('csdn','blog.csdn.net'); //The address of the blog name is csdn is blog.csdn.net(','blog.csdn.net/u011043843'); //The blog name is Danwang~The address of QiansiThe third type:
function test(setting){var defaultSetting={name:'Program enthusiast',age:'1',phone:'15602277510',QQ:'259280570',message:'Welcome to join'};$.extend(defaultSetting,setting);var msg='Name:'+defaultSetting.name+',age:'+defaultSetting.age+',phone:'+defaultSetting.phone+',QQ group:'+defaultSetting.QQ+', description:'+defaultSetting.message+'. ';alert(msg);}Call Example
test(); //Output: Name: Program enthusiast, age: 1, phone: 15602277510, QQ group: 259280570, description: Welcome to join. test({name:'dwqs',age:'20',QQ:'461147874',message:'Blog: www.VeVB.COM'});//Output: Name: dwqs, Age: 20, Phone: 15602277510, QQ group: 461147874, Description: Blog: www.VeVB.COM.ps: This method can be used when there are many functions. This is an extension of JQuery, so JQuery needs to be introduced.