function Blackboard( canvas){
this. socket = io. connect( 'http://'+ window. host+'/blackboard');
this. canvas = canvas;
this. ctx = this. canvas[ 0]. getContext( '2d');
this. ctxServer = this. canvas[ 0]. getContext( '2d');
this. drawing = false;
this. color = 'white';
this. width = 1;
this. colorServer = 'white';
this. widthServer = 1;
this. setEvent();
this. setServerEvent();
this. setShape();
this. color_map. forEach( element => {
$( '#pen_color'). append( $( ''). attr( 'value', element).text( element));
});
Array( 16). fill( 0). forEach(( element, index) => {
$( '#pen_width'). append( $( ''). attr( 'value', index+ 1).text( index+ 1));
});
}
알려줘 ㅠㅠ
this. socket = io. connect( 'http://'+ window. host+'/blackboard');
this. canvas = canvas;
this. ctx = this. canvas[ 0]. getContext( '2d');
this. ctxServer = this. canvas[ 0]. getContext( '2d');
this. drawing = false;
this. color = 'white';
this. width = 1;
this. colorServer = 'white';
this. widthServer = 1;
this. setEvent();
this. setServerEvent();
this. setShape();
this. color_map. forEach( element => {
$( '#pen_color'). append( $( ''). attr( 'value', element).text( element));
});
Array( 16). fill( 0). forEach(( element, index) => {
$( '#pen_width'). append( $( ''). attr( 'value', index+ 1).text( index+ 1));
});
}
알려줘 ㅠㅠ
머가 하고시프신거임
안됨 돌아가
마지막 foreach는 왜 쓴거냐..? 보니까 안에서 element(그것도 걍 0인..) 쓰지도 않는데
걍 this 생략하고 canvas = 3 이런거
개꼼수 쓰고 됨
range(1,16) 대신 쓴거얌
변수이름 키로해서 키만 있는 Object 만들고 with에 넣은다음 할당하면 됨
그니까 왜 그러냐고 무의미하게 데이터가 생성되는데.. 그냥 일반적인 for (let i = 어쩌구 루프 쓰지
교수님이 with쓰지말라셧는뎅
나지금 함수형 연습중이라 저렇게해바써
with는 원래 안쓰는게 맞고 this는 원래 쓰는게 맞음
this라는 글자를 치기 싫은거면 암거나 만들고 그거 반환하면 그거 기준으로 생성됨
함수형이랑 아무 상관 없음 그거.. 그리고 forEach는 콜렉션에 사이드 이펙트를 일으킬 때 쓰기 때문에 더더욱 이상하지
아냐 this를 꼭 써야되나 궁금햇던건데 꼭 써야되는거면 엋닐수없지
스택오버플로우에 for in range 구문 대체하는 함수형 구문 쳐봣는데 저거냐으던데
이미 있는 데이터이면서 그 데이터(여기서는 element)를 이용해 사이드 이펙트를 무조건 일으켜야 한다면 함수형 쓰는 사람들은 저렇게 쓸 수 있지. 하지만 지금은 그 경우가 아니라니까.
그럼 for(let a;a<16;a++) 대체하는 함수형구문이 먼데여
차라리 range(0, 16).forEach(iteratee) 를 해야지 range가 리스트 생성해주는 함수라 친다면
함수형 구문이 뭐다 이런게 중요한게 아니라 최대한 퓨어하고 조그만 함수들을 조립해서 큰 함수들을 만들어나가는게 함수형 프로그래밍의 대략적인 컨셉이라 할 수 있음
lodash 같은 걸로 한다치면 _.each(_.range(16), index => $('#pen_width').어쩌구 ) 이런 식으로 할 수 있겠지