Skip to content

Instantly share code, notes, and snippets.

@qfox
Last active August 29, 2015 14:12
Show Gist options
  • Save qfox/6536da74d9704d11a135 to your computer and use it in GitHub Desktop.
Save qfox/6536da74d9704d11a135 to your computer and use it in GitHub Desktop.
bem-entity.js
/**
* Scope creator
* @return {}
*/
function create () {
var undef;
/**
* BEM entity object
* @constructor
* @param {Object} props
*/
function BEMEntity(props) {
this.block = props.block;
if (props.elem) this.elem = props.elem;
if (props.modName) this.modName = props.modName;
if (props.modVal) this.modVal = props.modVal;
}
var ptp = BEMEntity.prototype;
ptp.elem = undef;
ptp.modName = undef;
ptp.modVal = undef;
/**
* BEMEntity public API
* @param {Object} props - block, elem, mod, val, etc.
* @return {BEMEntity}
*/
function BEMEntityFactory (props) {
return new BEMEntity(props);
};
BEMEntityFactory.create = create;
/**
* Object.defineProperty binded to BEMEntity.prototype
* @param {[type]} key [description]
* @param {Function} fn [description]
* @return {[type]} [description]
*/
BEMEntityFactory.defineProperty = function (key, fn) {
Object.defineProperty(ptp, key, {
get: fn,
enumerable: true
});
};
BEMEntityFactory.defineProperties = function (key, fns) {
var props = {};
for (var k in fns) {
if (!fns.hasOwnProperty(k)) continue;
props[k] = {
get: fns[k],
enumerable: true
};
}
Object.defineProperties(ptp, props);
};
return BEMEntityFactory;
}
/**
* BEMEntity factory
*/
module.exports = create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment