Last active
December 16, 2015 05:09
-
-
Save iamssen/5382327 to your computer and use it in GitHub Desktop.
object types 의 class property 에 초기값을 선언할 경우 static 과 같이 모든 class instance 에서 공유하는 현상이 생긴다. object 형태의 property 가 필요할 경우에는 constructor 에서 초기화 시키는 것이 좋다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('source-map-support').install() | |
class AAA | |
gl : null | |
constructor : (gl) -> | |
if not @gl? | |
@gl = | |
a : 1 | |
b : 2 | |
c : 3 | |
console.log(@gl, gl) | |
if gl? | |
if gl.a? then @gl.a = gl.a | |
if gl.b? then @gl.b = gl.b | |
if gl.c? then @gl.c = gl.c | |
a1 = new AAA | |
a2 = new AAA({ a : 5, b : 8 }) | |
a3 = new AAA({ c : 19 }) | |
a4 = new AAA | |
class BBB | |
a : 'aaaa' | |
constructor :(a) -> | |
console.log(@a, a) | |
@a = a | |
b1 = new BBB | |
b2 = new BBB('bbbb') | |
b3 = new BBB('cccc') | |
b4 = new BBB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment