javascriptnode.jslivescript

Livescript's clone operator ^^ doesn't work in the server side (node.js)


In livescript, we can use ^^ to clone an object.

For example,

consloe.log (^^{a:1})

will be compiled to

// Generated by LiveScript 1.2.0
(function(){
  console.log(clone$({
    a: 1
  }));
  function clone$(it){
    function fun(){} fun.prototype = it;
    return new fun;
  }
}).call(this);

However, these codes work successfully in browser but not in node.js.

What's the reason?


Solution

  • Properties of prototypes are not printed out by default. The ^^ operator sets the operand as the prototype of a new object. The properties are still are still accessible, but won't be printed by console.log and won't be serialized into JSON.

    If you simply want to copy over properties, use {} <<< obj.