我正在异步函数中使用等待按特定顺序执行函数,如果你看到这里 - 我想startAnim等到hideMoveUI完成执行后才能执行自己.
虽然我的控制台日志返回:
startAnim
hideMoveUI
Run Code Online (Sandbox Code Playgroud)
我的代码:
async function printAll() {
await hideMoveUI();
await startAnim();
}
printAll();
hideMoveUI = () => {
setTimeout(() => {
console.log('hideMoveUI');
}, 3000);
}
startAnim =() => {
setTimeout(() => {
console.log('startAnim');
}, 500);
}
Run Code Online (Sandbox Code Playgroud)
是setTimeout一种async功能?
如何使第二个功能等待第一个功能完成?任何帮助或建议表示赞赏.先感谢您.
我是React中的一个菜鸟,并尝试为用户输入数字的水相制作一个简单的应用程序,然后根据它应该显示水的状态的值,例如,如果他输入212它应该说气体和12它应该说实话,但由于某种原因它没有正确显示值,任何帮助非常感谢!!!
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
msg: "liquid",
temp: 0
};
this.handlenum1Change = this.handlenum1Change.bind(this);
}
handlenum1Change(evt) {
console.log(evt.target.value);
this.setState({
temp: Number(evt.target.value)
});
let temp = this.state.temp
if (temp > 100) {
this.setState({
msg: "boiling"
})
} else if (temp < 32) {
this.setState({
msg: "frozen"
})
} else {
this.setState({
msg: "liquid"
})
}
}
render() {
return (
<div>
<h1> {this.state.msg} </h1>
<form className="form-inline">
<div className="form-group">
<label> Temp: </label>
<input type="number" onChange={this.handlenum1Change} className="form-control" …Run Code Online (Sandbox Code Playgroud)我正在尝试使用异步函数来调用另一个函数内的函数。它看起来像这样:
const getConnectionsWithEmailsHash = async () => {
const connectionsWithEmails = await parseConnections('./tmp/connections.csv')
console.log(connectionsWithEmails)
return connectionsWithEmails
}
const connectionsWithEmailsHash = getConnectionsWithEmailsHash()
console.log(connectionsWithEmailsHash)
Run Code Online (Sandbox Code Playgroud)
当我在异步函数中使用 console.log() 时,我得到了我期望的哈希值,但是当我在 console.log() 中调用异步函数的结果时,我得到了未决的承诺。我虽然异步函数的重点是它在调用时等待承诺得到解决,所以我做错了什么?
我有一个字符数组(arr)和一个字符串(J),我想用这个array.reduce()方法来计算字符串J中存在的数组(arr)的字符数.
下面的代码显示了我如何使用array.reduce()方法,
let val = arr.reduce((count , ch) => {
return J.includes(ch) ? count + 1 : count
});
Run Code Online (Sandbox Code Playgroud)
但当我尝试使用样本值时,
arr = ?????[ 'a', 'A', 'A', 'S', 'S' ]?????;
J = 'aA';
Run Code Online (Sandbox Code Playgroud)
我得到了anser as
val = 'a11'
Run Code Online (Sandbox Code Playgroud) export interface Car {
Name: string;
Speed: number;
Manufactured: number;
}
const Speed: Car.Speed = 200;
Run Code Online (Sandbox Code Playgroud)
当前,Car.Speed正在导致错误:
无法访问“ Car.Speed”,因为“ Car”是一种类型,但不是名称空间。您是否要使用“ Car [“ Speed”]“在“ Car”中检索属性“ Speed”的类型?
因此,我有多个项目,每个项目都使用 TypeScript 的 diff 类型,因此我从全局卸载并将其放在我的项目本地,但当我运行 tsc 时,出现以下错误:
$ tsc --版本
内部/模块/cjs/loader.js:583
抛出错误;
^
错误:找不到模块 'C:\Program Files\nodejs\node_modules\typescript\bin\tsc'
在 Function.Module._resolveFilename (内部/modules/cjs/loader.js:581:15)
在 Function.Module._load (内部/modules/cjs/loader.js:507:25)
在 Function.Module.runMain (内部/modules/cjs/loader.js:742:12)
启动时(内部/bootstrap/node.js:283:19)
在 bootstrapNodeJSCore (内部/bootstrap/node.js:743:3)
根@DESKTOP-N8OLDFM /cygdrive/c/msweb/studiolite
$
我确实将以下内容添加到我的路径中:
/cygdrive/C/msweb/studiolite/node_modules/typescript/bin
有任何想法吗?
我有一个基类结构和几个继承的类.基类应该是纯虚拟类,它应该防止实例化.可以实例化继承的类.代码示例如下:
class BaseClass
{
public:
BaseClass(void);
virtual ~BaseClass(void) = 0;
};
class InheritedClass : public BaseClass
{
public:
InheritedClass1(void);
~InheritedClass1(void);
};
class DifferentInheritedClass : public BaseClass
{
public:
DifferentInheritedClass(void);
~DifferentInheritedClass(void);
};
Run Code Online (Sandbox Code Playgroud)
我想阻止以下操作发生:
InheritedClass *inherited1 = new InheritedClass();
DifferentInheritedClass *inherited2 = new DifferentInheritedClass ();
BaseClass *base_1 = inherited1;
BaseClass *base_2 = inherited2;
*base_1 = *base_2;
Run Code Online (Sandbox Code Playgroud) 我正在使用我的C++类中的自动摘要系统,并且对我正在进行的ASCII比较之一有疑问.这是代码:
char ch;
string sentence;
pair<char, char> sentenceCheck;
int counter = 0;
while (!ifs2.eof())
{
ch = ifs2.get();
ch = tolower(ch);
if (ch == 13)
ch = ifs2.get();
if (ch != 10 && ch != '?' && ch != '!' && ch != '.')
sentence += ch;
sentenceCheck.first = sentenceCheck.second;
sentenceCheck.second = ch;
cout << sentenceCheck.first << "-" << (int)sentenceCheck.first << " ---- " << sentenceCheck.second << "-" << (int)sentenceCheck.second << endl;
if(sentenceCheck.second == ' ' || sentenceCheck.second == 10 …Run Code Online (Sandbox Code Playgroud) 我正在尝试按一下按钮来显示输入上写的密码.我糟糕的JS技能告诉我,我可以通过做这样的事情来实现它:
我试过这个:
$('#passReveal').on('click', function(){
$( "#input-show" ).attr('type', 'text');
if ($( "#input-show" ).attr('type', 'text')){
$( "#input-show" ).attr('type', 'password');
}
});
Run Code Online (Sandbox Code Playgroud)
但是不起作用.
我认为这是最接近的,但我有一个错误:你必须点击两次按钮才能让它第一次工作,为什么会这样?
$('#passReveal').on('click', function(){
$( "#input-show" ).attr('type', 'text');
$( "#input-show" ).toggleClass('passRevealed');
if ($( "#input-show" ).hasClass('passRevealed')){
$( "#input-show" ).attr('type', 'password');
}
});
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/tepLkc7u/2/
我希望你明白我的英语不好,我正在学习:)
我创建了一个基本的HTML页面,其中有一个Login和Cancel按钮,但每当我点击按钮时,它允许我编辑按钮本身的文本.我检查了编码,看起来非常好.经过研究,我只得到有关如何编辑字段等文本的结果.我该如何解决这个问题?
这是我用来创建按钮的HTML编码:
<input class="button" onclick="check(this.form)" value="Login"><br /><br />
<input class="button" name="cancel" value="Cancel">
Run Code Online (Sandbox Code Playgroud)
这是我在按钮的CSS中使用的类:
.button {
display: inline-block;
text-align: center;
vertical-align: middle;
padding: 14px 62px;
border: 0px solid #2b27a1;
border-radius: 35px;
background: #2525f5;
background: -webkit-gradient(linear, left top, left bottom, from(#2525f5), to(#000326));
background: -moz-linear-gradient(top, #2525f5, #000326);
background: linear-gradient(to bottom, #2525f5, #000326);
text-shadow: #591717 1px 1px 1px;
font: normal normal bold 20px verdana;
color: #ffffff;
text-decoration: none;
}
.button:hover,
.button:focus {
border: 0px solid #453eff;
background: #2c2cff;
background: -webkit-gradient(linear, left top, left bottom, …Run Code Online (Sandbox Code Playgroud) javascript ×5
async-await ×2
c++ ×2
typescript ×2
arrays ×1
ascii ×1
asynchronous ×1
casting ×1
class ×1
cordova ×1
css ×1
html ×1
inheritance ×1
jquery ×1
node.js ×1
passwords ×1
reactjs ×1