'JavaScript'에 해당되는 글 43건

  1. 2006.08.27 Closures JavaScript
  2. 2006.08.27 Object-oriented JavaScript
  3. 2006.08.26 AOP in Javascript
참고로 난 아는언어는 Java밖에 없습니다..(사실은 자바도 허우덕 되고 있슴..ㅜ.ㅜ)
그래서 closures가 헤갈립니다.:)
하지만 현재 java jdk7버전부터 Closures가 지원될지도 모른다는 토비님의 포스팅을 보구
Closures을 잘몰라서  공부하기 시작했습니다.
(아직도 잘 이해가..영어를 잘해야겠다는 생각을 다시하게하는 하루였음)

What this means is that an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.

간단히 설명하면 inner function에서 outer function의 var,parameter를 접근하는것,outer function에서 return되었을때 조차도 var,parameter를 접근하는것을 말합니다.


참고 사이트
Closures JavaScript

javascript tip
Private static members in JavaScript
Understanding and Solving Internet Explorer Leak Patterns
JavaScript Closures
Javascript Closures
Leak Free Javascript Closures
Ecma-262
Posted by 전용우
,

난 전에는 javascript는 유효성체크하는 수준의 언어인줄 알고 있었다.

하지만 요즘 Ajax에 관심이 많아 공부를 하게 되니깐 생각보다 어렵고 재미있는 언어라는 사실을 알았다.

Object-oriented JavaScript
그중에서 제일 눈에 띄는 것은 자바와같이 객체처럼 사용할수 있다는것이다.

-code
function Pet(name) {
  this._name = name;
}
Pet.prototype._name;
Pet.prototype.getName = function() {
  return this._name;
}


-실행
var p = new Pet("Max");
alter(p.getName());

이걸보는순간..내가 만들었던 스크립트 코드들이 머리속을 지나가는 것은 무슨이유지?ㅡ;ㅡ


2차 충격  Inheritance

-code
function Dog(name) {
Pet.call(this, name);
}
Dog.prototype = new Pet();
Dog.prototype.wagTail = function() { alert("wagTail"); }

function Cat(name) {
Pet.call(this, name);
}
Cat.prototype = new Pet();
Cat.prototype.purr = function() { alert("Purring"); }

var d = new Dog("Max");
d.wagTail();
var c = new Cat("Fluffy");
c.purr();


실행
alert(d.getName());
alert(c.getName());

모든 객체지향프로그램에 등장하는 animal 예제 :)
위에서 보면 Pet을Cat,Dog에서 상속을 받아 getName()을 실행하고 있다.


마지막 충격.. ㅜ.ㅜ Polymorphism

-code
Pet.prototype.speak = function() {
  alert(this.getName() + " says...");
}
Dog.prototype.speak = function() {
  Pet.prototype.speak.call(this);
  alert("woof");
}
Cat.prototype.speak = function() {
  Pet.prototype.speak.call(this);
  alert("meow");
}

어떤가요? 신기 하지 않나요^^ 그리고 이글은 아래의 참고사이트에서 참고로 작성했습니다.

ps.아 그리고 java에서와 같이 public,private,privileged 란 개념이 존재하는군요.

참고사이트
Object-oriented JavaScript
Private Members in JavaScript

Posted by 전용우
,

AOP in Javascript

프로그래밍 2006. 8. 26. 03:34
Posted by 전용우
,