JavaScript

object, encapsulation, information hiding, interface

Naranjito 2021. 1. 11. 19:00

Object : One program consists of several types of logic. This logic can be groupping which consists of associated variables, methods. This is an object. It can be reused, it is a sort of components when it reused. So making a good object means recyclable in other places. For example, the initial computer which every parts such as monitor, harddist, keyboard is combined. But the newest one has each separate part.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>Document</title>
</head>
<body>
    <script>
        Object.prototype.contain=function(needle){
            for(var name in this){
                if(this[name]===needle){
                    return true;
                }
            }
            return false;
        }
        var o={'name':'aaa','age':'20'}
        //console.log(o.contain('aaa'));
        var a=['aaa','bbb','ccc'];
        //console.log(a.contain('bbb'));

        for(var name in o){//lets enumerate properties of o
            console.log(name);//it will return name and also property of object(contain)
        }

        for(var name in o){
            if(o.hasOwnProperty(name)){//has o name property by itself?
                //in this case, contain is the property inherited from parents, it doesnt appear, only properties of o appear
                console.log(name); 
            
        }


        
    </script> 
</body> 
</html> 

 

Encapsulation(Information hiding) : It is the bundling of data and the methods that act on that data such that access to that data is restricted from outside the bundle. It can be useable for anyone who knows how to use it. 

 

Interface : Exchangeable. For example, every computer parts made following the standard. It defines the specification of an entity. 

'JavaScript' 카테고리의 다른 글

prototype, random  (0) 2021.01.12
constructor, this  (0) 2021.01.12
arguments, function  (0) 2021.01.11
ajax, closure  (0) 2021.01.11
global variable, anonymous function  (0) 2021.01.07