Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Du JavaScript propre
Search
zenigata
June 13, 2013
Programming
280
0
Share
Du JavaScript propre
Compilation personnelle de quelques bonnes pratiques de codage en JavaScript.
zenigata
June 13, 2013
More Decks by zenigata
See All by zenigata
Refaire le SI d'une université catholique en 7 jours
zenigata
0
49
[REx] Mon premier train SAFe
zenigata
0
660
L'agilité vue par les animaux
zenigata
0
34
L'estimation AGILE démystifiée !
zenigata
1
180
Other Decks in Programming
See All in Programming
t *testing.T は どこからやってくるの?
otakakot
1
670
ハンズオンで学ぶクラウドネイティブ
tatsukiminami
0
130
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
360
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
110
[RubyKaigi 2026] Require Hooks
palkan
1
200
Swift Concurrency Type System
inamiy
0
530
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
140
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
150
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
150
ハーネスエンジニアリングとは?
kinopeee
10
5.4k
Making the RBS Parser Faster
soutaro
0
400
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Embracing the Ebb and Flow
colly
88
5k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
A Modern Web Designer's Workflow
chriscoyier
698
190k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Automating Front-end Workflow
addyosmani
1370
200k
The untapped power of vector embeddings
frankvandijk
2
1.7k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
260
Become a Pro
speakerdeck
PRO
31
5.9k
Transcript
Du JavaScript propre ce que j'ai retenu
Promis, j'arrête
Inline <div style="width: 800px; margin: 1em auto; font: bold 1em/1.2
Verdana, Arial, Helvetica, sans-serif"> <div style="float: left; width: 400px; padding: 1em 2em; font- size: 0.9em"> <span id="get-shit" onclick="callSomeFunction()">News</span> </div> </div>
Point-virgule, où es-tu ? var foo = function() { }
// parse error, semicolon expected test()
Espace de nommage pollué // global scope var foo =
42; function test() { // local scope foo = 21; } test(); foo; // 21
Eval c'est le mal var foo = 1; function test()
{ var foo = 2; var bar = eval; bar('foo = 3'); return foo; } test(); // 2 foo; // 3
Le changement c'est maintenant
Couverture de tests et CI
QUnit test("prettydate.format", function() { function date(then, expected) { equal(prettyDate.format("2008/01/28 22:25:00",
then), expected); } date("2008/01/28 22:24:30", "just now"); date("2008/01/28 22:23:30", "1 minute ago"); date("2008/01/28 21:23:30", "1 hour ago"); date("2008/01/27 22:23:30", "Yesterday"); date("2008/01/26 22:23:30", "2 days ago"); date("2007/01/26 22:23:30", undefined); });
Mocha test('display received results', function () { var sr =
new SearchResults(ul); sr.setResults(data); assert.equal(ul.find('.no-results').length, 0); assert.equal(ul.find('li.result').length, data.length); assert.equal( ul.find('li.result').first().attr('data-name'), data[0].name ); });
Module var counter = (function() { var privateValue = 0;
var publicMethod = function() { privateValue++; return privateValue; }; return { increment: publicMethod }; })(); // On passe à l'utilisation du compteur : counter.increment(); // 1 counter.privateValue; // undefined counter.privateValue = 0; counter.increment(); // 2
Classe // A car "class" function Car( model ) {
this.model = model; this.color = "silver"; this.year = "2012"; this.getInfo = function () { return this.model + " " + this.year; }; } var myCar = new Car("ford"); myCar.year = "2010"; console.log( myCar.getInfo() );
Package var myapp = { subpackage: { counter: (function() {
// ... })() } } // Et son utilisation : myapp.subpackage.counter.increment(); // 1
Design patterns Singleton Decorator Observer Prototype Factory MVC ...
Style guide
Webographie http://linsolas.github.io/blog/2013/04/03/devoxx-france-2013-du-javascript-propre-challenge-accepted/ http://coding.smashingmagazine.com/2012/06/27/introduction-to-javascript-unit-testing/ http://alistapart.com/article/writing-testable-javascript http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/ http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml http://contribute.jquery.org/style-guide/js/ https://github.com/styleguide/javascript http://addyosmani.com/blog/javascript-style-guides-and-beautifiers/ http://javascript.crockford.com/code.html
http://addyosmani.com/resources/essentialjsdesignpatterns/book/ http://bonsaiden.github.io/JavaScript-Garden/ http://ejohn.org/apps/learn/ http://www.eriwen.com/tools/perfect-front-end-build/ http://500px.com/photo/15306253 http://www.danescobar.com/albums/people/BRAWNY-20GIRLS_web.jpg