rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

README example is mutable #62

Closed neverfox closed 8 years ago

neverfox commented 8 years ago

I ran the first code example in a Node 4.1.1 console and everything that should not have mutated did. What could I be missing?

var Immutable = require('seamless-immutable');
var array = Immutable(["totally", "immutable", {hammer: "Can’t Touch This"}]);

array[1] = "I'm going to mutate you!"
array[1] // "I'm going to mutate you!"

array[2].hammer = "hm, surely I can mutate this nested object..."
array[2].hammer // "hm, surely I can mutate this nested object..."

for (var index in array) { console.log(array[index]); }
// "totally"
// "I'm going to mutate you!"
// { hammer: "hm, surely I can mutate this nested object..." }

JSON.stringify(array) // '["totally","I'm going to mutate you!",{"hammer":"hm, surely I can mutate this nested object..."}]'
damonmcminn commented 8 years ago

I have tried similar in Node 4.1.1, Node 0.12.7 and babel-node running on 4.1.1. I have also explicitly used an IIFE to ensure strict mode.

var list = Immutable([1,2,3])
list.pop()
console.log(list) // => [1,2]
davidchase commented 8 years ago

I've run into the same issue myself... and this issue https://github.com/rtfeldman/seamless-immutable/issues/50 seems related

damonmcminn commented 8 years ago

Many thanks!