Skip to content

Instantly share code, notes, and snippets.

@wycats
Created September 16, 2011 19:09
Show Gist options
  • Star 79 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save wycats/313496e6ba9160dc6eb5 to your computer and use it in GitHub Desktop.
Save wycats/313496e6ba9160dc6eb5 to your computer and use it in GitHub Desktop.
/**
* Copyright (C) 2011 by Yehuda Katz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/
// ligament.js is the smallest, lightest-weight JavaScript MVC framework.
//
// ligament.js requires modern browsers, which provide Object.create.
// Newer browsers are the future, older browsers are the past.
//
// If you really must support older browsers like IE8, you can use the
// hot polyfill for Object.create found at
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create
// Usage:
// MyModel = Object.create(M);
// instance = Object.create(MyModel);
// instance.firstName = "Brendan";
// instance.lastName = "Eich";
//
// Because ligament.js uses *real* prototype inheritance, like Spine, you can add new
// methods to the MVC layers by simply extending MVC objects:
// M.toString = function() { console.log("All models get this method!"); };
// Person = Object.create(M);
// Person.fullName = function() { return this.firstName + ' ' + this.lastName; }
// jeremy = Object.create(Person);
// jeremy.firstName = "Jeremy";
// jeremy.lastName = "Ashkenas";
// jeremy.fullName() //=> Jeremy Ashkenas
//
// That's it! Why deal with all the bloat of JavaScript frameworks. Use ligament.js!
M = {}, V = {}, C = {};
@sebslomski
Copy link

Is it web-scale?

@MattiSG
Copy link

MattiSG commented Sep 17, 2011

Microsoft said it is not the native HTML5 experience.

@postmodern
Copy link

Can someone port this to CoffeeScript?

@mark-ellul
Copy link

Can someone write a Jquery plugin for this please? ;)

@pedromtavares
Copy link

can you please write a wiki this is bad documentation tnx

@jeffreyiacono
Copy link

Can you provide the link to the Todo app that demonstrates Ligament.js usage? ;)

@likethesky
Copy link

I hear sinew.js is much more modern and cleaner than ligament, which is so, like "early September 2011"...

@NKjoep
Copy link

NKjoep commented Sep 18, 2011

and what about A/B testing? I need a framework for it...

@mxriverlynn
Copy link

don't forget about the coffeescript version! after all, no javascript mvc framework would be complete without it!

M = new (M = function(){
  this.M = function(){};
})()();

V = new (V = function(){
  this.V = function(){};
})()();

C = new (C = function(){
  this.C = function(){};
})()();

no... sorry... that's the version that coffeescript generated.

@mdesantis
Copy link

mdesantis commented Sep 18, 2011

and this is the minified version... for those who care about performance

@n1k0
Copy link

n1k0 commented Sep 18, 2011

okay but is it enterprise-ready?

@eliperelman
Copy link

For those that use MVVM and not MVC: https://gist.github.com/34d3bd7be864cced6188
:D

@lmcd
Copy link

lmcd commented Sep 30, 2011

Doesn't work in VB6

@amoln
Copy link

amoln commented Sep 30, 2011

The fwk needs 'Connect with Facebook/Twitter/LinkedIn' integration.

@giulianoliker
Copy link

My head just explo***BOOOOM***

@cayasso
Copy link

cayasso commented Sep 30, 2011

For those of you asking for testing this beast... wait no more:

console.log((M !== V && V !== C && C !== M) ? 'OK' : 'Not OK');
Who say it is not tested ah ah?
BTW. The test is only supported on modern browsers so no complains please!

@oroce
Copy link

oroce commented Oct 2, 2011

is there any 'in the wild' example?

Copy link

ghost commented Oct 5, 2011

this makes no sense. no sense at all! How the hell is this any different from just plain procedural js?

@MattiSG
Copy link

MattiSG commented Oct 5, 2011

@RassaR you clearly don't understand the MVC architecture. 🔥

Copy link

ghost commented Oct 6, 2011

@MattiSG great, I dont understand. Care you to restate something else that's as obvious as this?
that's WHY I asked the question!!!! Either answer it, or remain silent

@MattiSG
Copy link

MattiSG commented Oct 6, 2011

@RassaR Damn, man…

This gist is actually a joke. It makes fun of all the JS frameworks that all sell "MVC" as their main argument and motto, while MVC is an architecture, therefore not dependent on an implementation but rather on the respect of a simple concept: separate your models, views and controllers. Which something as simple as three different JS objects achieves, if used properly by the programmer.
You might have noticed that many comments ask for things even dumber: minified versions, plugins for X (X being whatever framework)… they all make fun of the newly found (~9 months - 1 year) JS frenzy where every framework / to-js-compiled-language has its zealots and it seemed necessary that JS code, to be credible, had a CoffeeScript version, a jQuery version, etc etc.

You may find the documentation at http://en.wikipedia.org/wiki/Sarcasm interesting to understand it better, if necessary. More generally, you might be interested in http://en.wikipedia.org/wiki/Humor. I actually thought you were into it too, as your comment could be understood as ironic (see http://en.wikipedia.org/wiki/Irony, might help).

In the same vein, see also: https://github.com/madrobby/vapor.js .

Is that clear enough an answer for you? :(

@lmcd
Copy link

lmcd commented Oct 6, 2011

Ignore this @MattiSG troll. ligament.js is a great way of embracing the MVC paradigm in JavaScript.

Copy link

ghost commented Oct 6, 2011

haha, awesome. I love the way you tought me a little of grammar and worldview...

So I am dumb, big deal. But I did build a app based on this M V C thing, and it worked! hahahahaha

@mdesantis
Copy link

@RassaR if you wrote an app based on ligament.js, please share it; ligament.js misses an example app.

@n1k0
Copy link

n1k0 commented Oct 6, 2011

UNSUBSCRIBE

@kurko
Copy link

kurko commented Oct 6, 2011

UNSUBSCRIBE +1

@likethesky
Copy link

@lmcd right on! That @MattiSG is a total troll. I'm so glad I have Ligament.js on my resume. Everyone, please tell ALL recruiters to add Ligament to their keyword searches, if they want to get the hottest JS coders. @RassaR please see http://theotherpages.org/quote-14.html for more examples of DWS ( http://acronyms.thefreedictionary.com/Dripping+with+Sarcasm ). @n1k0 @kurko please see https://github.com/account/notifications ("Comments after me on gists") @everyone else: Yeah, the long and the short of it is: we're all bored to tears, couldn't care less, we all know there's one born every minute, so I'm going to put my foot down, take one for the team, you know who you are: you can run but you can't hide, so ideally my post here is the kiss of death for this thread! (@RassaR see http://suspense.net/whitefish/cliche.htm ) :-D

@wjcrowcroft
Copy link

wjcrowcroft commented Oct 6, 2011 via email

@haochong
Copy link

cool

@g8d3
Copy link

g8d3 commented Aug 14, 2015

Which one should I use? this or ember?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment