2021. 5. 27. 20:14ㆍJava_Script
브라우저를 제어
사용자의 클립, 계산기, 달력 등의 "이벤트 조작"에 대응하기 위한 언어
기존방식:
"클릭 -> 다음화면 뿌려주기" 연속
JavaScript:
동적으로 데이터를 서버로 호출
#AJAX활용(구글맵) #Debug툴에 발전 #V8엔진 개발 #Nodejs 등장
변수선언:
var로 선언 (var a = 1; )
동적언어 이므로 자료형을 선언할 필요 x
기본자료형:
Boolean, Null, Undefined, Number, string, Symbol(ECMAScript 6에서 추가, 유일하고 변경 불가)
객체(Object)
chrome에서 실행:
F12(개발자 도구) -> console
배열:
한 배열안에 여러 자료형이 들어갈 수 있음
a.length : 배열의 크기
a.indexOf("nodejs"): 해당 자료의 인덱스를 도출
객체형으로 선언:
var a = new Array("100", "node")
var b = [];
화면에 출력: document.write('화면에 출력해줘')
줄바꿈: document.wirte('<br>')
함수 선언:
function day1(when){
document.write(when)
console.log(when)
}
day1("3월8일")
var day1 = function(when){
document.write(when)
console.log(when)
}
day1("3월8일")
var day1 = function(when){
return when;
}
console.write(day1("3월8일"));
value 선언:
function Car(a, b, c){
this.name = a; //public
this.color = b;
var move = c; //private
}
var a = new Car("테슬라", "red" , "직진")
console.log(a.name);
console.log(a.color);
console.log(a.move); // private라서 undifined로 나옴
프로토타입
Car.prototype.move = function(){ //car에서 this.name, this.color 넘어옴
console.log("차종: " + this.name + "차량색: " + this.color);
}
a.move();
var a = [1,2,4,5,6]
Array.prototype.print = function(){
for(var i=0; i<this.length; i++){
console.log(i);
}
}
a.print();
리터럴 객체
내가 인덱스를 정할 수 있고, 멤버와 벨류를 정할 수 있다.
var a = {
'a' : 110,
'b' : "hi",
'c' : function(){
console.log('ggg')
console.log(this.a);//내부에서 a에 접근하고 싶을 때
}
}
a.c();
console.log(a.b);
var a = (new Object()){}
cosole.log(typeof a);
Object.prototype.plus = function(){
console.log(this.a + 20);
}
'Java_Script' 카테고리의 다른 글
자바스크립트_기본 (0) | 2021.05.28 |
---|