Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Du JavaScript propre
Search
zenigata
June 13, 2013
Programming
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
53
[REx] Mon premier train SAFe
zenigata
0
670
L'agilité vue par les animaux
zenigata
0
38
L'estimation AGILE démystifiée !
zenigata
1
190
Other Decks in Programming
See All in Programming
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
8.8k
iOSDC2026登壇資料.pdf
riofujimon
0
190
速習iPhone Duo対応
yuukiw00w
2
840
新卒PdEのリアル
ryu1013
1
520
JRuby: Past, Present, and Future
headius
0
210
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
200
アクセシビリティから考える情報設計
high_g_engineer
0
420
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
180
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
200
App Intentsのビルドプロセスを支える技術
kntkymt
0
460
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
290
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Mobile First: as difficult as doing things right
swwweet
225
10k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
570
GraphQLとの向き合い方2022年版
quramy
50
15k
Writing Fast Ruby
sferik
630
63k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
KATA
mclloyd
PRO
35
16k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Making Projects Easy
brettharned
120
6.8k
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