var f = function() {
this.x = 5;
(function() {
this.x = 3;
})();
console.log(this.x);
};
f.call(f);
f();
f.call();
Run Code Online (Sandbox Code Playgroud)
var f
作为f.call(f)
输出运行5
。当作为f()
或f.call()
输出运行时3
。
在每种情况下会发生什么?内部功能this
指的是什么?
在使用 CRA v.1 创建的应用程序中,我需要运行特定的测试文件。我该怎么做?有一个--testPathIgnorePatterns
标志可以添加到npm test
脚本中以忽略文件或路径,但是如何从命令行使用 CRA 运行特定的测试文件?
下面的 codegen.ts 配置会导致RegisterDocument
条目重复。
代码生成器.ts:
const config: CodegenConfig = {
overwrite: true,
schema: "http://localhost:4000/graphql",
documents: "src/graphql/**/*.graphql",
generates: {
"src/generated/graphql": {
preset: "client",
plugins: [
"typescript-urql"
],
config: {
documentVariableSuffix: 'test2'
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
输出:
export const RegisterDocument = {"kind":"Document", ...}
export const RegisterDocument = gql`
mutation Register($username: String!, $password: String!) {
register(options: {username: $username, password: $password}) {
errors {
field
message
}
user {
id
username
createdAt
}
}
}
`;
export function useRegisterMutation() {
return Urql.useMutation<RegisterMutation, RegisterMutationVariables>(RegisterDocument); …
Run Code Online (Sandbox Code Playgroud) 当我打开然后关闭 Flatpickr 实例而不选择日期时,它会将其设置为今天的日期。如何防止这种行为?当用户未设置时,我需要日期输入保持为空。
Flatpickr 实例用 React-Flatpickr 包装。
<Flatpickr
ref={fpStartDate}
className='th-input-container__input'
value={startDate}
onClose={(selectedDates, dateStr, instance) => {
if (selectedDates.length > 0) {
setInputValue(1);
setCurrentPage(1);
setStartDate(selectedDates[0]);
}
}}
options={{
enableTime: true,
enableSeconds: true,
dateFormat: 'd.m.Y, H:i:S',
locale: Russian,
mode: 'single',
time_24hr: true,
minuteIncrement: 1,
allowInput: true,
disableMobile: true,
monthSelectorType: 'dropdown',
onOpen: function(selectedDates, dateStr, instance) {
setTimeout(function() {
instance.open();
}, 200);
}
}}
placeholder='from'
/>
Run Code Online (Sandbox Code Playgroud) 我的配置是这样。
WebStorm 2018.1.4; ESLint 6.4; 节点12.8; npm 6.10.2;Windows 8.1。
如何消除线程标题中的错误?
这是一个代码示例。
import {
GET_DAILY_SUCCESS,
GET_HOURLY_SUCCESS,
GET_MINUTE_SUCCESS
} from './types';
import {
getDailyToUsd,
getHourlyToUsd,
getMinuteToUsd
} from '../api/cryptocompare';
import { setError } from './error';
export const getDaily = (fsym = 'BTC') => async dispatch => {
try {
const list = await getDailyToUsd(fsym);
dispatch({
type: GET_DAILY_SUCCESS,
currency: fsym,
list
});
} catch(err) {
dispatch(setError(err.Message));
}
};
Run Code Online (Sandbox Code Playgroud) 在我的 React Hooks 应用程序中,我需要让用户在输入字段中键入 1000 毫秒。当 1000 毫秒到期时,将发送带有输入值的 API 请求。
<input type='text' name='name' className='th-input-container__input' onChange={evt => testFunc2(evt.target.value)} />
Run Code Online (Sandbox Code Playgroud)
该值设置为testFunc2(evt.target.value)
:
const testFunc2 = useCallback(debounce((text) => setNameFilter(text), 1000), []);
Run Code Online (Sandbox Code Playgroud)
一旦nameFilter
设置为新值,useEffect
就会发出 API 请求,因为nameFilter
它是依赖项。这样,仅使用最终的用户输入而不是每个击键值来查询 API,但输入仍不受控制。当我将当前nameFilter
值添加到输入时,value={nameFilter}
用户无法在输入中键入,并且输入仅接收最后键入的字符。
如何让用户输入的字符显示在输入中?
WebStorm以我喜欢的方式产生单行样式注释,并在//
:后面留空格// comment here
。在注释掉代码块时,如何在前导注释文字之后和结尾处添加空格?这是我所拥有的:
/*<line of code>
<line of code>
<line of code>*/
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
/* <line of code>
<line of code>
<line of code> */
Run Code Online (Sandbox Code Playgroud)
Add a space at comment start
不会的
webstorm ×2
debouncing ×1
eslint ×1
flatpickr ×1
javascript ×1
react-hooks ×1
reactjs ×1
this ×1
unit-testing ×1