'closure'에 해당되는 글 2건

  1. 2011.11.09 Closure Linter 알아보기
  2. 2008.02.20 objects, collections, linkage, invocations, this, typeof, closure, namespace, inheritance

Closure Linter 알아보기

ITWeb/개발일반 2011.11.09 17:06
원래는 javascript 의 정적분석을 위해서 closure inspector 를 사용하려 했으나.. firefox 버전과 firebug 버전을 좀 타서.. 그냥.. 안하기로 했다.
걍.. checkstyle 이나 적용해 봅시다.

Windows 버전임돠!! (cygwin 설치 하셔서 하시면 더 편하실거예요.. )


http://www.python.org/download/releases/ : version 호환성때문에 2.7 설치함.
http://pypi.python.org/pypi/setuptools#windows (다운로드) : 2.7 설치함. (easy_install)

- python 과 setuptools 모두 exe 파일 이므로 실행 시켜서 설치 하시면 됩니다.

[Closure Linter 설치]
- python 이 설치된 폴더로 이동
- Python27\Scripts 로 이동
- cmd 창에서 easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz
- 다운로드가 잘안되거나 에러 발생할 경우 수동으로 다운로드 받아서 아래 처럼 설치
easy_install closure_linter-latest.tar.gz

[gjslint 실행]
- 역시 Python27\Scripts 로 이동
- cmd 창에서 실행
- gjslint D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

C:\Python27\Scripts>gjslint D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

----- FILE  :  D:\Workspace\jee\jsunit_prototype\UnitTC\index.js -----

Line 2, E:0005: Illegal tab in whitespace before "var"

Line 4, E:0005: Illegal tab in whitespace before "if"

Line 5, E:0005: Illegal tab in whitespace before "div.innerHTML"

Line 6, E:0005: Illegal tab in whitespace before "}"

Found 4 errors, including 0 new errors, in 1 files (0 files OK).

Some of the errors reported by GJsLint may be auto-fixable using the script

fixjsstyle. Please double check any changes it makes and report any bugs. The

script can be run by executing:

fixjsstyle D:\Workspace\jee\jsunit_prototype\UnitTC\index.js

- fixjsstyle 을 실행 시켜면 이넘이 수정해 줄수 있는건 자동으로 수정을 해줍니다.
- 위에 보이는 에러는 tab 을 space 4 로 바꾸지 않고 그냥 tab 문자로 사용을 해서 발생한 오류 입니다.
- eclipse 에서 editor 설정과 fomatter 변경 하시면 됩니다.

[compiler 수동실행]

D:\Development>java -jar closure-compiler\compiler.jar --js D:\Workspace\jee\jsunit_prototype\UnitTC\index.js --create_source_map D:\Workspace\jee\jsunit_prototype\UnitTC\index-map --js_output_file D:\Workspace\jee\jsunit_prototype\UnitTC\index-compiled.js

- 이렇게 하면 compiled 된 js 파일이 D:\Workspace\jee\jsunit_prototype\UnitTC\ 경로에 생성 됩니다.


'ITWeb > 개발일반' 카테고리의 다른 글

javascript event 맛보기.  (0) 2011.11.10
jslint 돌려보기.  (0) 2011.11.09
Closure Linter 알아보기  (0) 2011.11.09
Google Closure Compiler  (0) 2011.11.09
jsunit 알아보기.  (0) 2011.11.09
JSCoverage 알아보기.  (0) 2011.11.08
Trackback 0 : Comment 0

objects, collections, linkage, invocations, this, typeof, closure, namespace, inheritance

ITWeb/개발일반 2008.02.20 16:36

-Everything else is objects
-Objects can contain data and methods
-Objects can inherit from other objects.

-An object is an unordered collection of name/value pairs
-Names are strings
-Values are any type, including other objects
-Good for representing records and trees
-Every object is a little database
§var FUNC = function () {
§ var objDiv = document.createElement("div");
§ this.getCollection = function ( collection ) {
§ for ( i in collection ) {
§ objDiv.innerHTML += "name : " + i + "<br>value : " + collection[i] + "<br>";
§ }
§ document.body.appendChild(objDiv);
§ }
§FUNC = new FUNC();

Object Literals
-Object literals are wrapped in { }
-Names can be names or strings
-Values can be expressions
-: separates names and values
-, separates pairs
-Object literals can be used anywhere a value can appear

-Objects can be created with a secret link to another object.
-If an attempt to access a name fails, the secret linked object will be used.
-The secret link is not used when storing. New members are only added to the primary object.
-The object(o) function makes a new empty object with a link to object o.

function object(o) {
function F() {};
F.prototype = o;
return new F();

JavaScript Invocations
-If a function is called with too many arguments, the extra arguments are ignored.
-If a function is called with too few arguments, the missing values will be undefined.
-There is no implicit type checking on the arguments.
-There are four ways to call a function:
§Function form
§Method form
§Constructor form
new functionObject(arguments)
§Apply form
functionObject.apply(thisObject, [arguments])

JavaScript this
-this is an extra parameter. Its value depends on the calling form.
-this gives methods access to their objects.
-this is bound at invocation time.
Invocation form
the global object
the object
the new object

JavaScript typeof

-The scope that an inner function enjoys continues even after the parent functions have returned.
-This is called closure.
§function getClosure () {
§  var num = 1;
§  var getAlert = function() { num++; alert(num); }
§  num++;
§  return getAlert();
§<input type="button" value="getClosure" onclick="getClosure();">

function fade(id) {
    var dom = document.getElementById(id),
        level = 1;
    function step () {
        var h = level.toString(16);
        dom.style.backgroundColor =
            '#FFFF' + h + h;
        if (level < 15) {
            level += 1;
            setTimeout(step, 100);
    setTimeout(step, 100);

JavaScript Namespace
-Every object is a separate namespace.
-Use an object to organize your variables and functions.
-The YAHOO Object.
§var YAHOO = {};
§YAHOO.url = "http://www.yahoo.com";
§YAHOO.getUrl = function () {
§ alert(this.url);
§ return this.url;
§<input type="button" value="YAHOO.getUrl();" onclick="YAHOO.getUrl();">

-Linkage provides simple inheritance.
-Prototypal inheritance.
-Parasitic inheritance.
-Method apply(), call().

Trackback 0 : Comment 0