- attribute : It called attribute within object
<!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>
var MYAPP={}//MYAPP is a global variable
MYAPP.calculator={ //calculator is an attribute
'left':null,//null means undefined the value
'right':null
}
MYAPP.coordinate={
'left':null,
'right':null
}
MYAPP.calculator.left=10;
MYAPP.calculator.right=20;
function sum(){
return MYAPP.calculator.left+MYAPP.calculator.right;
}
document.write(sum());
(function(){ //anonymous function
var MYAPP={}//MYAPP is a local variable
MYAPP.calculator={
'left':null,
'right':null
}
MYAPP.coordinate={
'left':null,
'right':null
}
MYAPP.calculator.left=10;
MYAPP.calculator.right=20;
function sum(){
return MYAPP.calculator.left+MYAPP.calculator.right;
}
document.write(sum());
}())
var i = 5;
function a(){
var i=10;
b();
}
function b(){
document.write(i);//in this case, i returns 5 because it used when it defined
}
</script>
</body>
</html>
'JavaScript' 카테고리의 다른 글
arguments, function (0) | 2021.01.11 |
---|---|
ajax, closure (0) | 2021.01.11 |
global variable, local variable (0) | 2021.01.07 |
.push(), .concat(), .unshift(), .splice, .shift(), .pop(), .reverse() (0) | 2021.01.07 |
UI, API, Regular Expression, .exec, .test, i, g, (), $, \, \s (0) | 2021.01.07 |