Denny Lim <hello@iamdenny.com>
<iamdenny@nhn.com>
A language mechanism for restricting access to some of the object's components
원하지 않는 무언가로부터 변수를 보호한다.
function Human(sGender){
//Private
this._nAge = 1;
this._sGender = sGender || 'Male';
//Public
this.growUp = function(){
this._nAge++;
}
}
function Human(sTempGender){
//Private
var nAge = 1,
sGender = sTempGender || 'Male';
//Privileged Method
this.growUp = function(){
nAge++;
}
}
function Human(sTempGender){
//Private
var nAge = 1,
sGender = sTempGender || 'Male';
//Public
return {
growUp : function(){
nAge++;
}
}
}
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
define(id?, dependencies?, factory);
define(
'account',
['service', 'pubsub'],
function(service, pubsub){
// Private Code
// export public APIs
return {
signIn : function(){},
signOut : function() {},
getName : function() {},
setName : function() {}
}
}
);
(function(){
// Private Code
exports = {
signIn : function(){},
signOut : function() {},
getName : function() {},
setName : function() {}
};
define('account', function(){
return exports;
}
}());
define('jindo', [], function() {return jindo;} );
define('jquery', [], function() {return jQuery;} );
<script type="text/javascript" src="require.js"></script>
<script type="text/javascript" src="main.js"></script>
require(['app'], function(app){
app.init();
});
define(['lib/account', 'lib/sesstion'],
function(account, session){
// 내부 코드
return {
init : function(){}
}
}
);