mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-01 12:45:49 +02:00
Updated Style Guide (markdown)
parent
bf8ee744b3
commit
33da82fbf1
@ -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, ...) {
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user