Skip to content

Instantly share code, notes, and snippets.

View kyuwoo-choi's full-sized avatar
🎖️
Hello, New World!

KyuWoo Choi kyuwoo-choi

🎖️
Hello, New World!
View GitHub Profile
@kyuwoo-choi
kyuwoo-choi / book-collection-aop-proxy.js
Created June 14, 2017 16:15
hello world AOP - proxy
...
function Logger(target, pattern) {
return new Proxy(target, {
get: function(obj, prop) {
var value, name;
if (!Reflect.has(obj, prop)) {
return;
}
name = target.name || target.constructor.name;
value = Reflect.get(obj, prop);
@kyuwoo-choi
kyuwoo-choi / book-collection-aop-decorator.js
Created June 14, 2017 16:16
hello world AOP - decorator
function wove(pattern) {
return function (target) {
target.prototype = Logger(target.prototype, pattern);
};
}
@wove(/^get.*/)
class BookCollection {
getNameByISBN(isbn) {
@kyuwoo-choi
kyuwoo-choi / book-collection-aop-decorator-equals.js
Created June 14, 2017 16:18
hello world AOP - decorator equal
wove(/^get.*/)(BookCollection);
@kyuwoo-choi
kyuwoo-choi / book-collection-aop-no-need.js
Created June 14, 2017 16:20
hello world AOP no need?
let originalFunction = Collection.prototype.getNameByISBN;
Collection.prototype.getNameByISBN = function () {
let result = originalFunction.apply(this, arguments);
Logger.info(`Retrieving ${result.isbn} - ${result.name} has been succeed`);
return result;
};
<!DOCTYPE html>
<html>
<head>
<script src="../src/CurrentTime.js"></script>
</head>
<body>
<current-time>
<!-- fallback value -->
6/11/2017, 11:55:49
</current-time>
class CurrentTime extends HTMLElement {
constructor() {
// 클래스 초기화. 속성이나 하위 노드는 접근할 수는 없다.
super();
}
static get observedAttributes() {
// 모니터링 할 속성 이름
return ['locale'];
}
connectedCallback() {
<!DOCTYPE html>
<html>
<head>
<script src="../src/CurrentTime.js"></script>
</head>
<body>
<div class="current-time">
<!-- fallback value -->
6/11/2017, 11:55:49
</div>
class CurrentTime {
constructor(el) {
this._el = el;
this._init();
this.start();
}
_init() {
// 속성 변경을 모니터
this._localeChangedObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
<div class="user-profile">
<div class="layout card small">...</div>
</div>
<user-profile>
<card-layout type="small">...</card-layout>
</user-profile>
// 자바스크립트 컨트롤을 묶을 엘리먼트를 받아와야 한다.
constructor(el) {
this._el = el;
}
...
// 이 클래스 인스턴스가 `유지하는 엘리먼트`의 innerText
this._el.innerText = 'text';
...
// 클래스 인스턴스와 엘리먼트의 라이프사이클은 다르다.
// bootstrap