File: JSDCE-objectPattern.js

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (29 lines) | stat: -rw-r--r-- 706 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Of all these, only d must remain: the others are defined in the function, and
// used from that scope, not the global scope.
let a = 10;
let b = 20;
let c = 30;
let d = 40;

// This one must also remain: z in the function is not a local variable, but the
// id in an object, so it does not affect scoping at all, and we use the global
// z.
let z = 50;

globalThis.f = function([/*empty*/, r]) {
  let { a, b } = r;
  let { z: c } = r;
  let [/*empty*/, i, {foo : p, bar : q}] = r;
  return g(a, b, c, d, z);
};

// As above, but now with array destructuring.
let a2 = 10;
let b2 = 20;
let c2 = 30;
let d2 = 40;

globalThis.f2 = function(r2) {
  let [ a2, b2, c2 ] = r2;
  return g2(a2, b2, c2, d2);
};