This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript syntax to set a default value | |
var text = someString || "default text"; | |
var text2 = someString || someString2 || "default text2"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var frozenObject = { | |
value1 : 1, | |
value2 : 2 | |
}; | |
Object.freeze(frozenObject); | |
console.log(Object.isFrozen(frozenObject)); // true | |
// 삭제 불가 | |
delete frozenObject.value1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sealedObject = { | |
value1 : 1, | |
value2 : 2 | |
}; | |
Object.seal(sealedObject); | |
console.log(Object.isSealed(sealedObject)); // true | |
// 삭제 불가 | |
delete sealedObject.value1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var preventExtensionObject = { | |
value1 : 1, | |
value2 : 2 | |
}; | |
Object.preventExtensions(preventExtensionObject); | |
console.log(Object.isExtensible(preventExtensionObject)); // false | |
// 삭제 가능 | |
delete preventExtensionObject.value1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepFreeze(obj){ | |
if (!Object.isFrozen(obj)){ | |
Object.freeze(obj); | |
} | |
for (var key in obj) { | |
if ({}.hasOwnProperty.call(obj, key) || !(typeof obj[key] === 'function' || typeof obj[key] === 'object' && !!obj[key])) { | |
continue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function jsonp(url, callback) { | |
var callbackName = 'jsonp_' + Math.round(100000 * Math.random()); | |
window[callbackName] = function(data) { | |
delete window[callbackName]; | |
document.body.removeChild(script); | |
callback(data); | |
}; | |
var script = document.createElement('script'); | |
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName; | |
document.body.appendChild(script); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD 환경 | |
define(['exports', 'jquery'], factory); | |
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { | |
// CommonJS 환경 | |
factory(exports, require('jquery')); | |
} else { | |
// 일반 브라우저 | |
factory((global.module1 = global.module1 || {}), global.$); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(['exports'], factory); | |
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { | |
factory(exports); | |
} else { | |
factory((global.module1 = global.module1 || {})); | |
} | |
}(this, function (exports) { | |
exports.action = function () {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, factory) { | |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | |
typeof define === 'function' && define.amd ? define(['exports'], factory) : | |
(factory((global.module1 = global.module1 || {}))); | |
}(this, (function (exports) { | |
exports.action = function () {}; | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var throttleFunction = (function() { | |
'use strict'; | |
var timeWindow = 500; // 여기에 시간(ms)을 지정한다 | |
var lastExecution = new Date((new Date()).getTime() - timeWindow); | |
// ES6 이하일 경우 ...args에 호출할 parameter 만큼 준다 function(arg1, arg2...) | |
var throttleFunction = function(...args) { | |
// 여기에 로직을 구현한다 | |
}; |