A function inside a class modifies prototype instead of just returning an object

StackOverflow https://stackoverflow.com/questions/15735182

  •  31-03-2022
  •  | 
  •  

Question

I have this code in LiveScript (1.1.1):

class A
  b = -> { a: 1 b: 2 }

It compiles into this:

var A;
A = (function(){
  A.displayName = 'A';
  var b, prototype = A.prototype, constructor = A;
  b = function(){
    return prototype.a = 1, prototype.b = 2, prototype;
  };
  function A(){}
  return A;
}()); 

Why does b() modify prototype? I expected it to just return a { a: 1, b: 2 } associative array.

Was it helpful?

Solution

It's because of this : https://github.com/gkz/LiveScript/commit/d49b3ee8e8e2d5d7b9f128fa98c210b582e095fe

Which should probably be removed then, mmh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top