Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Named-parameters/JavaScript/named-parameters-1.js
Normal file
12
Task/Named-parameters/JavaScript/named-parameters-1.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function example(options) {
|
||||
// assign some defaults where the user's has not provided a value
|
||||
opts = {}
|
||||
opts.foo = options.foo || 0;
|
||||
opts.bar = options.bar || 1;
|
||||
opts.grill = options.grill || 'pork chops'
|
||||
|
||||
alert("foo is " + opts.foo + ", bar is " + opts.bar + ", and grill is " + opts.grill);
|
||||
}
|
||||
|
||||
example({grill: "lamb kebab", bar: 3.14});
|
||||
// => "foo is 0, bar is 3.14, and grill is lamb kebab"
|
||||
12
Task/Named-parameters/JavaScript/named-parameters-2.js
Normal file
12
Task/Named-parameters/JavaScript/named-parameters-2.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let
|
||||
example = // The member name in the object can either be the same as the parameter (as in bar, grill),
|
||||
// or a different parameter name as in the case of member foo being assigned to parameter a here.
|
||||
({foo: a=0, bar=1, grill='pork chops'}={}) => (
|
||||
console.log('foo is ',a,', bar is ',bar,', and grill is '+grill));
|
||||
|
||||
example();
|
||||
// foo is 0 , bar is 1 , and grill is pork chops
|
||||
example({grill: "lamb kebab", bar: 3.14});
|
||||
// foo is 0 , bar is 3.14 , and grill is lamb kebab
|
||||
example({foo:null});
|
||||
// foo is , bar is 1 , and grill is pork chops
|
||||
Loading…
Add table
Add a link
Reference in a new issue