표준 내장객체(Standard Built-in Object) : 자바스크립트가 기본적으로 가지고 있는 객체들이다. 프로그래밍을 하는데 기본적으로 필요한 도구들이기 때문에 중요하다.
  - Object
  - Function
  - Array
  - String
  - Boolean
  - Number
  - Math
  - Date
  - RegExp

예제
//
var arr = new Array('seoul','daejeon','daegu','pusan', 'gwangju');
function getRandomValueFromArray(arr){
    var index = Math.floor(arr.length*Math.random());
    return arr[index];
}
console.log(getRandomValueFromArray(arr));

 

//
Array.prototype.random = function(){
    var index = Math.floor(this.length*Math.random());
    return this[index];
}
var arr = new Array('seoul','daejeon','daegu','pusan', 'gwangju');
console.log(arr.random());

 

Object 객체 : 객체의 가장 기본적인 형태를 가지고 있는 객체다. 아무것도 상속받지 않는 순수한 객체이며. 값을 저장하는 기본적인 단위로 사용한다.
예시
<!DOCTYPE html>
<html>
<head>
 <title></title>
</head>
<body>
<script type="text/javascript">

//Object.keys()
var arr=["a","b","c"];
console.log('Object.keys(arr)',Object.keys(arr));

//Object.prototype.toString()
var o = new Object();
console.log('o.toString()', o.toString());

var a = new Array(1,2,3);
console.log(a.toString()', a.toString());
</script>
</body>
</html>

 

//
Object.prototype.contain = function(neddle) {
    for(var name in this){
        if(this[name] === neddle){
            return true;
        }
    }
    return false;
}
var o = {'name':'egoing', 'city':'seoul'}
console.log(o.contain('egoing'));
var a = ['egoing','leezche','grapittie'];
console.log(a.contain('leezche'));

 

'Programming > Javascript' 카테고리의 다른 글

복제, 참조, 함수  (0) 2018.01.03
데이터 타입, 래퍼객체  (0) 2018.01.03
상속, prototype  (0) 2018.01.03
전역객체와 this  (0) 2018.01.03
생성자와 new  (0) 2018.01.03
블로그 이미지

꼴통보안인

,