KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
BeautifulProperties.js
★ 17
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
brennus
:
Builder pattern to generate java classes
gevent-threading-comparison
:
An experiment to compare the performances of gevent and threading.
DarkSky.py
:
A Python interface to Dark Sky -- DEPRECATED
android-shell
:
Utility class to give Android applications a shell interface.
pin-php
:
PHP implementation of Pin's Payment API.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
BeautifulProperties.js
?
Download (.md)
BeautifulProperties.js - Extension of ECMAScript5 property. =========================================================== Links ===== - [Repository](https://github.com/monjudoh/BeautifulProperties.js) - [Reference](http://monjudoh.github.io/BeautifulProperties.js/docs/index.html) Features ======== LazyInitializable ----------------- BeautifulProperties.LazyInitializable.define can define a property, it's initialized at first access. ``` {.sourceCode .javascript} var proto = {}; BeautifulProperties.LazyInitializable.define(proto,'boundFunction',function(){ return (function () { console.log(this); }).bind(this); }); var object1 = Object.create(proto); object1.a = 1; var boundFunction1 = object1.boundFunction; boundFunction1();// {a:1,boundFunction:fn} var object2 = Object.create(proto); object2.a = 2; var boundFunction2 = object2.boundFunction; boundFunction2();// {a:2boundFunction:fn} ``` Hookable -------- BeautifulProperties.Hookable.define supports hooks for setting/getting property,replace or modify value. hooks ``` {.sourceCode .javascript} var object = {}; BeautifulProperties.Hookable.define(object,'key'); BeautifulProperties.Hookable.addHook(object,'key','beforeInit',function(val){ console.log('beforeInit',val); return val; }); BeautifulProperties.Hookable.addHook(object,'key','afterInit',function(val){ console.log('afterInit',val); }); BeautifulProperties.Hookable.addHook(object,'key','beforeGet',function(){ console.log('beforeGet'); }); BeautifulProperties.Hookable.addHook(object,'key','afterGet',function(val){ console.log('afterGet',val); return val; }); BeautifulProperties.Hookable.addHook(object,'key','beforeSet',function(val,previousVal){ console.log('beforeSet',val,previousVal); return val; }); BeautifulProperties.Hookable.addHook(object,'key','afterSet',function(val,previousVal){ console.log('afterSet',val,previousVal); }); object.key = 1; object.key = 2; object.key; ``` modify getting value ``` {.sourceCode .javascript} var object = {}; BeautifulProperties.Hookable.define(object,'key'); BeautifulProperties.Hookable.addHook(object,'key','afterGet',function(val){ return val * 2; }); object.key = 1; object.key;//2 ``` modify setting value ``` {.sourceCode .javascript} var object = {}; BeautifulProperties.Hookable.define(object,'key'); BeautifulProperties.Hookable.addHook(object,'key','beforeInit',function(val,previousVal){ return val * 2; }); BeautifulProperties.Hookable.addHook(object,'key','beforeSet',function(val,previousVal){ return val * 3; }); object.key = 1; object.key;//2 object.key = 1; object.key;//3 ``` Events ------ ``` {.sourceCode .javascript} var object = {}; BeautifulProperties.Events.on(object,'eventType',function(ev){ console.log('event handler is called.'); }); BeautifulProperties.Events.trigger(object,'eventType'); ``` event bubbling. A event bubble up to the prototype of the object. ``` {.sourceCode .javascript} var proto = {}; var object = Object.create(proto); BeautifulProperties.Events.on(proto,'eventType',function(ev){ console.log('event handler is called.'); }); BeautifulProperties.Events.trigger(object,'eventType'); ``` controlling event bubbling. ``` {.sourceCode .javascript} var ancestor = {}; var object = {}; BeautifulProperties.Events.Ancestor.setRetriever(object,function(){ return ancestor; }); BeautifulProperties.Events.on(ancestor,'eventType',function(ev){ console.log('event handler is called.'); }); BeautifulProperties.Events.trigger(object,'eventType'); ``` Observable ---------- BeautifulProperties.Observable.define supports key/value observation. ``` {.sourceCode .javascript} var object = {}; BeautifulProperties.Observable.define(object,'key'); BeautifulProperties.Events.on(object,'init:key',function(ev,val){ console.log(val);// val:1 }); BeautifulProperties.Events.on(object,'change:key',function(ev,val,previousVal){ console.log(val,previousVal);// val:2,previousVal:1 }); object.key=1; object.key=2; ``` Installation and usage ====================== In browsers: ------------ ``` {.sourceCode .html} <script src="BeautifulProperties.js"></script> ``` In an AMD loader like RequireJS: -------------------------------- ``` {.sourceCode .javascript} require(['BeautifulProperties'], function(BeautifulProperties) { }); ``` Changelog ========= 0.2.0 ----- - changed - It trigger init:{key} event when Observable property is initialized. - removed - BeautifulProperties.Hookable.addHooks method - BeautifulProperties.Internal namespace - context property of BeautifulProperties.Events\~BindingOptions 0.1.12 ------ - added - Multiple binding is supported in BeautifulProperties.Events. - changed - context property of BeautifulProperties.Events\~BindingOptions is renamed to thisObject. - deprecated - context property of BeautifulProperties.Events\~BindingOptions 0.1.11 ------ - fixes - event.previousTarget,event.currentTarget in BeautifulProperties.Events.Ancestor\~ancestorRetriever. 0.1.10 ------ - added - BeautifulProperties.Events.Event\#previousTarget property - changed - BeautifulProperties.Events.Ancestor\~ancestorRetriever callback - has 2 params. - If the ancestorRetriever returns undefined,Ancestor.retrieve method returns the prototype of the target object. 0.1.9 ----- - Export as global,AMD,CJS. - Many refacotoring. - deprecated - BeautifulProperties.Hookable.addHooks method - BeautifulProperties.Internal namespace is deprecated. - removed - BeautifulProperties.getRaw method (deprecated since 0.1.6) - BeautifulProperties.setRaw method (deprecated since 0.1.6) Author ====== monjudoh <https://github.com/monjudoh> Contributors ============ - aodag (Atsushi Odagiri) <https://github.com/aodag> - He named this library. - jbking (Yusuke Muraoka) <https://github.com/jbking> - He provides ideas for this library.