From 2bb80186f15d860cd5e17934c270bd0814236004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Bo=CC=88hlmark?= Date: Thu, 13 Oct 2011 23:47:59 +0200 Subject: [PATCH] Added documentation for stopHere-flag on remove and delete --- README.markdown | 4 ++-- test/mutability.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index 053dc2d..f86ef76 100644 --- a/README.markdown +++ b/README.markdown @@ -131,13 +131,13 @@ Set a new value for the present node. All the elements in `value` will be recursively traversed unless `stopHere` is true. -this.remove() +this.remove(stopHere=false) ------------- Remove the current element from the output. If the node is in an Array it will be spliced off. Otherwise it will be deleted from its parent. -this.delete() +this.delete(stopHere=false) ------------- Delete the current element from its parent in the output. Calls `delete` even on diff --git a/test/mutability.js b/test/mutability.js index d536239..2236f56 100644 --- a/test/mutability.js +++ b/test/mutability.js @@ -98,19 +98,19 @@ exports.remove = function () { }; exports.removeNoStop = function() { - var obj = { a : 1, b : 2, c : { d: 3, e: 4 } }; + var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 }; - var keysWithoutStop = []; + var keys = []; Traverse(obj).forEach(function (x) { - keysWithoutStop.push(this.key) + keys.push(this.key) if (this.key == 'c') this.remove(); }); - assert.deepEqual(keysWithoutStop, [undefined, 'a', 'b', 'c', 'd', 'e']) + assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f']) } exports.removeStop = function() { - var obj = { a : 1, b : 2, c : { d: 3, e: 4 } }; + var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 }; var keys = []; Traverse(obj).forEach(function (x) { @@ -118,7 +118,7 @@ exports.removeStop = function() { if (this.key == 'c') this.remove(true); }); - assert.deepEqual(keys, [undefined, 'a', 'b', 'c']) + assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'f']) } exports.removeMap = function () {