Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
132 captures
17 Apr 2013 - 12 May 2025
JanFEBMar
04
201620172018
success
fail
COLLECTED BY
Organization:Alexa Crawls
Starting in 1996,Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to theWayback Machine after an embargo period.
Collection:Alexa Crawls
Starting in 1996,Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to theWayback Machine after an embargo period.
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20170204083608/http://cocktailjs.github.io:80/

CocktailJS

ANNOTATIONS. TRAITS. TALENTS.

LEARN MORE

READ OUR DOCS

Follow @CocktailJSView in GitHub
What's it?

CocktailJS is a small library forNodeJS to help developers defining classes and modules in abetter, more readable and organised way. It also explores other technics toreuse code such asAnnotations,Traits andTalents.

For Who?

For those developers who likes Object Oriented Programming, CocktailJS helps to extendyour classes without utils, to define modules, and to keep code structure more visuallyappealing making the code easier to understand and debug.

Why

There is one principle behind CocktailJS’s design:Keep code simple, readable and reusable.Simplicity is key in any design, and writing code is not an exception to that rule.

Mix

The entry point in Cocktail is a method namedmix(). As in any cocktail, youmix things up. In the mix we can use an existing Object, Module or Class referenceand mix it to add more value, like adding more properties or even methods.

Mix Object Example

varcocktail=require('cocktail'),obj={name:'My Object'};cocktail.mix(obj,{value:10,print:function(){console.log(this.name+' '+this.value);}});obj.print();//MyObject 10

Read more:Quick Start

Annotations

Annotations aremeta-data CocktailJS uses to apply some processes. As meta-data,they are not part of the resulting mix, they are declarative and they bring readabilityon your code.

A Class Example (Car.js)

varcocktail=require('cocktail');cocktail.mix({'@exports':module,'@as':'class','@properties':{make:'',model:'',year:null},constructor:function(make,model,year){this.setMake(make);this.setModel(model);this.setYear(year);}});

Read more:Class Definitions

Traits

Traits areComposable Units of Behaviour (You can read more fromthis paper).Basically, a Trait is a Class, but a special type of Class that has only behaviour (methods) and no state.Traits are an alternative to reuse behaviour in a more predictable manner. They are more robust thanMixins, orMultiple Inheritance since name collisions must be solved by the developer beforehand. If you compose your classwith one or more Traits and you have a method defined in more than one place, your program will fail giving no magic ruleor any kind of precedence definition.

varcocktail=require('cocktail'),Login=require('./trait/login');cocktail.mix({'@exports':module,'@as':'class','@traits':[Login]});

Read More:Starting with Traits

Talents

Talents are very similar to Traits, in fact a Trait can be applied as a Talent in CocktailJS. The main difference is that a Talent can be applied to anobject ormodule.So we can define a Talent as aDynamically Composable Unit of Reuse(you can read more fromthis paper).

Note: While almost all functionality is implemented, the only missing part from the original paper is the ability to remove a Talent from a given instance.

varcocktail=require('cocktail'),Login=require('./trait/login'),user=require('./user');cocktail.mix(user,{'@talents':[Login]});

Read More:Exploring Talents

Install CocktailJS Now!

Usenpm to install and save it to your project.

$npm install cocktail --save

Latest Updates

blog/Traits with ES7 Decorators

03 Jul 2015
es7traits-decoratorbabeldecoratorbind-operator

In this post we are going to explore how to use ES7 features to define traits with a brand new module:traits-decorator.

blog/CocktailJS v0.7.0 Released

04 Mar 2015
release

A new version of CocktailJS!CocktailJS v0.7.0 is available onnpm!As with all other releases, we try to keep all functionality backward compatible until the very first of 1.0 is released.

extensions/Advisable

02 Feb 2015
traitstalents

A Trait to addAOP advices into Classes/Objects. The methodsaround,after andbefore are available on host classes or objects.


[8]ページ先頭

©2009-2025 Movatter.jp