var x = 5; var result; try{ result = x * y; document.writeln(result); } catch(e){ document.writeln(e); }finally{ document.writeln('ok'); } /* result : ReferenceError: y is not defined ok */ try{ result = x / 0; document.writeln(result); throw new Error('0으로 나눌 수 없습니다.'); } catch(e){ document.writeln(e); document.writeln('
'); }finally{ document.writeln('ok'); document.writeln('
'); } /* result : 5 Error: 0으로 나눌 수 없습니다. ok */ try{ var calculator; calculator = calculator || {add : function(op1, op2){ return op1 + op2; }}; calculator && document.write(calculator.add(2,3)); calculator && document.write(calculator.sub(2,3)); }catch(e){ document.write(e); } /* result : 5 TypeError: calculator.subtract is not a function */
'2014/01'에 해당되는 글 18건
- 2014.01.13 [JavaScript] try..catch..finally
- 2014.01.10 [JavaScript] for...in
- 2014.01.10 [aptana] 설정
- 2014.01.10 [JavaScript] Short-circuit logical operator
- 2014.01.10 [JavaScript] undefined와 null
- 2014.01.10 [JavaScript] 리터럴(Literal)
- 2014.01.09 [Java] interface
- 2014.01.09 [Java] abstract
for...in 문은 객체의 프로퍼티나 배열의 원소에 대해 순서대로 반복처리를 실행
변수에는 객체로부터 나온 프로퍼티명이 저장되거나, 배열로부터 나온 인덱스번호가 저장된다.
for( 변수 in "객체" or "배열"){
}
var arr = [ {name: '정도전', age: 50}, {name: '이성계', age: 60}, {name: '정몽주', age: 54}, {name: '이방원', age: 43} ]; for(var idx in arr){ for(var prop in arr[idx]){ document.writeln(prop + ' : ' + arr[idx][prop]); if(prop == 'age'){ break; } } }
확장자 추가
Perferences > General > Content Types > Add
테마 변경
Perferences > Aptana Studio> Theme > 변경
jQuery 자동완성 쓰기
메뉴 > Commands > Bundle developer > install bundle > jquery 선택
폰트
Verdana
첫번째 값을 평가한후 뒤에 값을 평가하지 않는것.
//논리 연산자 /* var aa = false; var bb = true; aa && bb // bb 평가x aa || bb // bb 평가 */ var calculator; // &&연산에서 좌측 표현식이 undefined값을 가지면 //false로 평가되어 우측 평가식을 실행하지 않는다. calculator && document.writeln("calcuator.add(2,3):" + calculator.add(2,3)); calculator = { add : function(op1, op2){ return op1 + op2; } }; // && 연산에서 좌측 표현식이 0, undefined, null, NaN, "" 이외의 값을 가지면 // true로 평가되어 우측평가식이 실행됩니다. calculator && document.writeln("calcuator.add(2,3):" + calculator.add(2,3)); // || 연산에서 좌측 표현식이 undefined값을 가지면 false로 평가되어 우측 평가식을 실행함. calculator.subtract || (calculator.subtract = function(op1, op2){ return op1 - op2; }); calculator.subtract || document.writeln("calcuator.subtract (2,3):" + calculator.subtract (2,3));
undefined
- 변수가 선언은 되었지만 값이 할당된 적이 없는 변수에 접근하건, 존재하지 않은 객체 프로퍼티에 접근할 경우 반환되는 값.
- 논리 연산에서 false로,
산술연산에서는 NaN로,
문자열 연산에서는 "undefined"로 변환되어 연산됨.
null
- 예약어
- 보통 참조 타입과 함께 쓰여, 어떠한 객체도 나타내지 않는 특수한 값으로 사용
- 논리 연산에서는 false로,
산술연산에서는 0으로,
문자열 연산에서는 "null"로 변환되어 연산됨.
//undefined와 null var a; var obj = {}; document.writeln('a: '+ a);//a: undefinde document.writeln('obj: '+ obj);//obj: [object Object] document.writeln('obj.prop: '+ a);//a: obj.prop:: undefined obj = null; //객체 참조를 제거 document.writeln("obj: " + obj);//obj : null if(!a){} //!undefined if(!obj){} //!null
리터럴(Literal) : 프로그램의 코드상에 데이터의 값을 표현하는 방식
자바스크립트의 리터럴 :
- 숫자 리터럴, 문자열 리터럴, 배열 리터럴, 객체 리터럴, 함수 리터럴, 블리언 리터럴, undefined와 null 리터럴
interface
- abstract 클래스의 한 종류로 포함 멤버의 제약을 가짐(순수 디자인 목적)
- 다중 상속이 가능한 유일한 클래스
interface의 포함 멤버
- public static final 멤버 필드
- public abstract 멤버 메서드
- public static inner 클래스
interface AAA{ //모두 동일 public static int a = 0; public static final int b = 100; public final int c = 200; public int d = 300; public abstract void aaa(); public void bbb(); void ccc(); } interface E{} interface F extends E{} interface G{} interface H extends E, G{} class I{} class J implements E, G{} class K extends I implements E, G{}
abstract 메서드
- 메서드의 내용부가 정의 되지 않은 형태로 모델 개념의 메서드
- 반드시 오버라이딩 되어야 사용 가능
abstract class AA{ public abstract void aaa(); }
abstract 클래스
abstract 클래스
- abstract 메서드를 포함하고 있는 클래스로 다형성 표현으로 사용
- 객체를 발생시킬 수 없는 것을 제외하면 일반 클래스와 동일
function helloSyntaxHighlighter() { return "hi!"; }