From 33da82fbf1b43e7677a9386a3b77b639f7d3fcc4 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 16 May 2021 13:26:10 +0200 Subject: [PATCH] Updated Style Guide (markdown) --- Style-Guide.md | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Style-Guide.md b/Style-Guide.md index 2101439..9d99352 100644 --- a/Style-Guide.md +++ b/Style-Guide.md @@ -45,6 +45,25 @@ if (someVar === conditionA) { Variables must be defined only once within a function scope, preferably at the top of the function. Use `const` if the value is not mutated and `let` if it is mutated. In new code we don't use `var` unless absolutely necessary. ## Classes +For new code the following way of creating classes should be used: + +```javascript +class ClassName { + constructor(...) { + ... + } + + functionName(arg1, arg2, ...) { + ... + } + + aVeryVeryVeryVeryVeryLongFunctionName + (arg1, arg2, ...) { + ... + } +} +``` + The standard way of creating classes in PDF.js used to be the following, so you might see this pattern in the current code base. Please note that by class we mean an object that is class-like. ```javascript @@ -66,22 +85,4 @@ var ClassName = (function ClassNameClosure() { return ClassName; })(); -``` - -However, we are in the process of converting our code to ES6 syntax since classes are generally available in browsers and well optimized nowadays, so for new code we prefer the following way of creating classes. - -```javascript -class ClassName { - constructor(...) { - ... - } - - functionName(arg1, arg2, ...) { - ... - } - - aVeryVeryVeryVeryVeryLongFunctionName - (arg1, arg2, ...) { - ... - } -} \ No newline at end of file +``` \ No newline at end of file