본문 바로가기

책을읽자

[자바스크립트 코딩 기법과 핵심 패턴] 유용한 가이드

반응형
자바스크립트 코딩 기법과 핵심 패턴 - 8점
스토얀 스테파노프 지음, 김준기.변유진 옮김/인사이트

저자가 아무래도 더글라스 크락포드의 영향을 많이 받은 듯 합니다. 앞부분 1장부터 4장까지는 마치 '자바스크립트 핵심 가이드'를 복습하는 것이 아닌가 싶을 정도로 같은 이야기가 반복됩니다. 저자 소개를 보면 더글라스 크락포드의 책에 대한 기술 리뷰를 담당했다고 합니다. 더글라스가 JSON 형식이라든지 JSLint를 만든 것처럼 저자 역시 smuch.it와 같은 도구를 만드는 것을 즐기는 듯 합니다.

본문에서 다루는 내용 중 많은 내용은 실제 야후!에서 개발한 코드를 참조하는 내용이 많습니다. 물론 책을 쓰기 위해 코드는 일부 변경했겠지만 실제로 현장에서 적용하는 코드라는 점을 강조하고 있습니다.


이 책 역시 기초를 살짝 다루기는 하지만 활용서에 가깝기 때문에 처음 프로그래밍 언어를 다루는 분을 위한 책은 아닙니다. '자바스크립트 핵심 가이드'와 비교한다면 이 책을 나중에 읽는 것이 좋겠네요. 앞에서 이야기했듯 인용해서 설명하는 부분이 많거든요.


꼭 자바스크립트가 아니더라도 일에 대한 좋은 이야기도 남겨놓았습니다.

...The first solution may be a working solution, but it’s nothing more than a draft, one example way to solve a problem. The second solution will always be better, because you now have a much deeper understanding of the problem. In the second solution, you’re also not allowed to copy-paste from the first one, which helps prevent you from taking shortcuts or settling for the nonperfect solution...


...generous and consistent spacing makes the code easier to read allowing it to "breathe"...


그리고 왜 이런 식으로 코드를 짜는지에 대한 궁금함도 어느 정도 풀어주고 있습니다. 기초 단계에서는 일단 따라해보세요~였다면 이 책에서는 왜 이렇게 코드를 짜는지 나름 상세하게 풀어주고 있습니다.

...There is a small potential benefit because the code evaluated in new Function() will be running in a local function scope, so any variables defined with var in the code being evaluated will not become globals automatically. Another way to prevent automatic globals is to wrap the eval() call into an immediate function...


...The case against function declarations and the reason to prefer function expressions is that the expressions highlight that functions are objects like all other objects and not some special language construct...


...But the methods work on primitives, too—as soon as you invoke a method, the primitive is temporarily converted to an object behind the scenes and behaves as if it were an object...


가끔 약간의 개그 코드도 들어있는데 잘 드러나지는 않는다는 ~

팩토리 패턴 예제 중에 아래와 같은 예제가 있습니다.

var corolla = CarMaker.factory('Compact');

var solstice = CarMaker.factory('Convertible');

var cherokee = CarMaker.factory('SUV');

corolla.drive(); // "Vroom, I have 4 doors"

solstice.drive(); // "Vroom, I have 2 doors"

cherokee.drive(); // "Vroom, I have 17 doors"


오~ cherokee는 문이 17개나 있었나? 싶어 오타가 아닌가 찾아보았는데 errata 페이지에 저자가 살짝 멘트를 남겼네요.


...To me 17 looks exaggerated enough but a little funnier and nonsensical being a prime :)

http://www.oreilly.com/catalog/errata.csp?isbn=9780596806767


* 2010년 야후!를 떠나 페이스북으로 자리를 옮겼습니다. 최근 React: Up & Running: Building Web Applications 라는 책을 준비하고 있나 봅니다.

http://www.amazon.com/React-Running-Building-Web-Applications/dp/1491931825


얼마 전에는 F8 행사에서 잠시 얼굴을 비추기도 했습니다.

http://www.phpied.com/f8-2015/



* '자바스크립트 핵심 가이드'는 좋고 나쁜 점이 살짝 애매한 부분이 있는데 이 책에서는 잘못된 부분과 추천하는 방법을 잘 표현해주고 있습니다. 물론 이 책이 쓰여진 시점의 웹브라우저 환경과 지금은 좀 다르긴 하지만 여전히 좋은 패턴은 배울 것이 많습니다.

728x90