Skip to content

Instantly share code, notes, and snippets.

@anekos
Created January 25, 2010 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anekos/285774 to your computer and use it in GitHub Desktop.
Save anekos/285774 to your computer and use it in GitHub Desktop.
// 以下の assert は全部通る。
let a1 = [{}, 1, 2];
let a2 = a1.concat();
assertEqual('A0', false, function () a1 === a2);
assertEqual('A1', false, function () a1 === ({}));
assertEqual('A2', true, function () a1[0] === a2[0]);
let b1 = [{}, 1, 2];
let b2 = b1.concat();
b1[0]['hoge'] = 'moge';
assertEqual('B0', false, function () b1 === b2);
assertEqual('B1', true, function () b1[0] === b2[0]);
assertEqual('B2', 'moge', function () b1[0].hoge);
assertEqual('B3', 'moge', function () b2[0].hoge);
let c1 = [['moge'], 1, 2];
let c2 = c1.concat();
c1[0][0] = 'hage';
assertEqual('C0', false, function () c1 === c2);
assertEqual('C1', true, function () c1[0] === c2[0]);
assertEqual('C2', 'hage', function () c1[0][0]);
assertEqual('C3', 'hage', function () c2[0][0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment