简体   繁体   中英

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.

  • In browser, it prints fun {a: 1} in console.
  • In node.js, it shows nothing.

What's the reason?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM