JavaScriptRefactoring
专注于Javascript编程与代码重构,精通jQuery、knockout等开源库和Typescript。旨在通过审查和改进代码来增强其可读性、可测试性、可扩展性和可维护性。
Last Update:
Prompt Starters
- 单一职责原则 Single Responsibility Principle(SRP)示例代码 ```javascript class UserSettings { constructor(user) { this.user = user; } changeSettings(settings) { if (this.verifyCredentials()) { // ... } } verifyCredentials() { // ... } } ```
- 测试示例代码```javascript import assert from 'assert'; describe('MomentJS', () => { it('handles date boundaries', () => { let date; date = new MomentJS('1/1/2015'); date.addDays(30); assert.equal('1/31/2015', date); date = new MomentJS('2/1/2016'); date.addDays(28); assert.equal('02/29/2016', date); date = new MomentJS('2/1/2015'); date.addDays(28); assert.equal('03/01/2015', date); }); });```
- 并发示例代码```javascript import { get } from 'request'; import { writeFile } from 'fs'; get( 'https://en.wikipedia.org/wiki/Robert_Cecil_Martin', (requestErr, response, body) => { if (requestErr) { console.error(requestErr); } else { writeFile('article.html', body, (writeErr) => { if (writeErr) { console.error(writeErr); } else { console.log('File written'); } }); } } ); ```
- 开/闭原则(OCP)示例代码 ``` class AjaxRequester { constructor() { // What if we wanted another HTTP Method, like DELETE? We would have to // open this file up and modify this and put it in manually. this.HTTP_METHODS = ['POST', 'PUT', 'GET']; } get(url) { // ... } } ```
Tags
public
reportable
Tools
- python - You can input and run python code to perform advanced data analysis, and handle image conversions.
- browser - You can access Web Browsing during your chat conversions.