Skip to content

Instantly share code, notes, and snippets.

(function () {
var
global = this,
ArrProto = global.Array.prototype,
proto_slice = ArrProto.slice,
proto_map = ArrProto.map,
proto_reduce = ArrProto.reduce,
@petsel
petsel / components.Enumerable_first_last.js
Last active December 16, 2015 05:29
Trait example for "Enumerable" that implements only two methods [first] and [last]
/**
* see also / derived from:
* [https://github.com/petsel/composable/blob/master/src/components/Enumerable/Enumerable.first-last-item.js]
* [https://github.com/petsel/composable/blob/master/src/composites/Array/Array.first-last.js]
*/
var Enumerable_first_last = (function () {
var
Trait, // the "Enumerable_first_last" Trait Module.
@petsel
petsel / components.Introspective_isFunction_isCallable.js
Last active December 16, 2015 05:29
Trait example for "Introspective" that implements only two methods [isFunction] and [isCallable]
/**
* see also / derived from:
* [https://github.com/petsel/composable/blob/master/src/components/Introspective/Introspective.isFunction-isCallable.js]
* [https://github.com/petsel/composable/blob/master/src/composites/Function/Function.isFunction-isCallable.js]
*/
var Introspective_isFunction_isCallable = (function () {
var
Trait, // the "Introspective_isFunction_isCallable" Trait Module.
@petsel
petsel / components.Observable_SignalsAndSlots.js
Last active December 16, 2015 05:29
Mixin example for "Observable" that implements the Signal Slot concept and provides a configurable API for [addEventListener], [removeEventListener], [hasEventListener] and [dispatchEvent]
/**
* see also / derived from:
* [https://github.com/petsel/composable/blob/master/src/components/Observable/Observable.SignalsAndSlots.js]
* [https://github.com/petsel/composable/blob/master/src/composites/Queue/QueueFactory.js]
*/
var Observable_SignalsAndSlots = (function () {
var
global = this,
@petsel
petsel / type-composition-example_Traits-Mixin-and-Factory.js
Last active December 17, 2015 09:59
composing a Queue type from a Queue Factory component. The whole system integrates 5 composable components - an Observable Mixin, two different Allocable and three different Enumerable Traits.
var Enumerable_first_last = (function () {
var
Trait,
first = function () {
return this[0];
},
last = function () {
return this[this.length - 1];
@petsel
petsel / Function.modifiers.adviceTypes.afterThrowing-afterFinally
Last active December 17, 2015 10:08
prototypal implementations of one full set and two complementary partial sets of AOP inspired method modifiers - [Function.prototype.before], [Function.prototype.after], [Function.prototype.afterThrowing], [Function.prototype.afterFinally] and [Function.prototype.around].
/**
* see also / derived from:
* [https://github.com/petsel/composable/blob/master/src/components/Controllable/Controllable.adviceTypes.afterThrowing-afterFinally.js]
* [https://github.com/petsel/composable/blob/master/src/composites/Function/Function.modifiers.adviceTypes.afterThrowing-afterFinally.js]
*/
(function (Function) {
@petsel
petsel / __thoughts-about-how-to-adopt-principles-of-aop-to-javascripts-dynamic-and-functional-nature.md
Last active December 17, 2015 23:39
1) thoughts about how to adopt the principles of aspect oriented programming to JavaScripts dynamic and functional nature.2) point (1) now gets accompanied by a working implementation - "modification.ao.js" - of an aspect oriented system as proof of concept.3) there is a working "logging" example now too as always if one needs to justify the exi…

roughly sketched

  • runtime based only and not using any kind of JavaScript "transpilers" or JavaScript build tools for "code weaving" as in e.g. AspectJ.
  • thus being forced focusing on what ES3 language core does provide.
  • implementation of prototypal method modifiers e.g. Function.prototype.before, Function.prototype.after, Function.prototype.around as minimal set of a kind of an AOP base that already supports library / framework agnostic modification of function based control flow by just wrapping additional behaviors / advice handlers around existing methods / functions.
  • clarify role of Joinpoint, Pointcut, Advice, Aspect; especially from this point of view of what makes them distinct from existing approaches in compiled and/or non dynamic and/or non functional programming languages.

@petsel
petsel / The-many-Talents-of-JavaScript.md
Last active February 21, 2017 11:33
The-many-Talents-of-JavaScript.md

#The many »Talents« of JavaScript

[TOC]

##The many talents of JavaScript for generalizing Role Oriented Programming approaches like Traits and Mixins

###TL;DR / Summary

@petsel
petsel / Die-vielen-Talente-von-JavaScript.md
Created June 5, 2014 10:10
Die-vielen-Talente-von-JavaScript.md

#Die vielen »Talente« von JavaScript

[TOC]

##Die vielen Talente von JavaScript Rollen-orientierte Programmieransätze wie Traits und Mixins verallgemeinern zu können

###TL;DR / Abriss

@petsel
petsel / Function.toApplicator.js
Last active December 23, 2016 10:00
Prevent function based "Role" pattern implementations[1] like "Mixin"s, "Trait"s or "Talent"s from getting instantiated by turning them into callable objects. Thus creating real objects but providing [call] and [apply] as standard call/delegation methods to them.
/**
*
* Prevent function based "Role" pattern implementations[1] like "Mixin"s,
* "Trait"s or "Talent"s from getting instantiated by turning them into
* callable objects. Thus creating real objects but providing [call] and
* [apply] as standard call/delegation methods to them.
*
* The concept will be promoted as "Applicator" in order to distinguish
* it from "Constructor". (Though in theirs wording both do follow the
* same track.)