Skip to content

Commit 1fcdbda

Browse files
authored
refactor: replace prototype to class syntax (#4151)
1 parent 0768d02 commit 1fcdbda

File tree

7 files changed

+390
-403
lines changed

7 files changed

+390
-403
lines changed

lib/box/file.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22

33
const { readFile, readFileSync, stat, statSync } = require('hexo-fs');
44

5-
function File({ source, path, params, type }) {
6-
this.source = source;
7-
this.path = path;
8-
this.params = params;
9-
this.type = type;
10-
}
11-
12-
File.prototype.read = function(options, callback) {
13-
return readFile(this.source, options).asCallback(callback);
14-
};
5+
class File {
6+
constructor({ source, path, params, type }) {
7+
this.source = source;
8+
this.path = path;
9+
this.params = params;
10+
this.type = type;
11+
}
1512

16-
File.prototype.readSync = function(options) {
17-
return readFileSync(this.source, options);
18-
};
13+
read(options, callback) {
14+
return readFile(this.source, options).asCallback(callback);
15+
}
1916

20-
File.prototype.stat = function(options, callback) {
21-
if (!callback && typeof options === 'function') {
22-
callback = options;
23-
options = {};
17+
readSync(options) {
18+
return readFileSync(this.source, options);
2419
}
2520

26-
return stat(this.source).asCallback(callback);
27-
};
21+
stat(options, callback) {
22+
if (!callback && typeof options === 'function') {
23+
callback = options;
24+
options = {};
25+
}
2826

29-
File.prototype.statSync = function(options) {
30-
return statSync(this.source);
31-
};
27+
return stat(this.source).asCallback(callback);
28+
}
29+
30+
statSync(options) {
31+
return statSync(this.source);
32+
}
33+
}
3234

3335
File.TYPE_CREATE = 'create';
3436
File.TYPE_UPDATE = 'update';

0 commit comments

Comments
 (0)