Last active
December 29, 2015 22:29
-
-
Save glassesfactory/7736445 to your computer and use it in GitHub Desktop.
需要あるかわからんし車輪の再発明臭すごいけどクラスメソッドを継承と言うか無理やりバインドする
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
class BaseHoge | |
@foo:()-> | |
console.log "bar" | |
@extends:(kls)-> | |
props = [] | |
o = @ | |
while o | |
props = props.concat Object.getOwnPropertyNames o | |
o = Object.getPrototypeOf o | |
props = _.uniq(props) | |
props = _.difference(props, gy.objProps) | |
for name in props | |
kls[name] = @[name] if typeof @[name] is "function" and name not in kls |
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
class ExtendHoge extends BaseHoge | |
constructor:()-> | |
BaseHoge.extends ExtendHoge | |
$ -> | |
BaseHoge.foo() | |
#result... | |
# bar |
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
### | |
俺々便利 utils. | |
何回か投稿してるので5枚集めるとおもちゃの缶づm(ry | |
### | |
do(window)-> | |
gy = | |
getPropNames:(target)-> | |
props = [] | |
o = target | |
while o | |
props = props.concat Object.getOwnPropertyNames o | |
o = Object.getPrototypeOf o | |
#プロパティ名を一意にする | |
props = _.uniq props | |
return props | |
do -> | |
#Object のプロパティ一覧を出して継承の対象外リストとする | |
gy.objProps = gy.getPropNames Object | |
#super も対象外リストに追加 | |
gy.objProps.push "__super__" | |
gy.window = gy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment