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
0
280
Du JavaScript propre
Compilation personnelle de quelques bonnes pratiques de codage en JavaScript.
zenigata
June 13, 2013
Tweet
Share
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
650
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
CSC307 Lecture 13
javiergs
PRO
0
320
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
260
SourceGeneratorのマーカー属性問題について
htkym
0
190
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
130
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
240
CSC307 Lecture 15
javiergs
PRO
0
240
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
430
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
840
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
720
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
140
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
2
110
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
BBQ
matthewcrist
89
10k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
440
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
67
37k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Making Projects Easy
brettharned
120
6.6k
It's Worth the Effort
3n
188
29k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
75
Paper Plane
katiecoart
PRO
0
48k
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