我有几种方法可以返回我希望能够从类外部调用的 jsx 对象,目前,我发现该工作的唯一方法是从同一个文件中的类外部导出箭头函数,但我最终得到类外的函数太多。
那么有没有办法从同一个文件中导出多个类方法并将它们保存在类中?
我不想为这些函数中的每一个都创建一个新类,因为它们是相关的,我需要将它们从类中调用出来,以便我能够将它们添加到 Storybook 中。
我想要的例子:
//A.js
class A{
export foo() {return (<div>...</div>)}
export bar() {...}
}
export default A
Run Code Online (Sandbox Code Playgroud)
我现在所拥有的:
//A.js
export default class A{
...
}
export const foo = () => {...}
export const bar= () => {...}
Run Code Online (Sandbox Code Playgroud) 如果在循环的条件部分中进行大量计算,运行时是否存在差异?
例如:
int i,n;
for(i=1;i<=[call to some complex function on n];i++)
...
Run Code Online (Sandbox Code Playgroud)
要么
int i,n,foo;
foo=[call to some complex function on n];
for(i=1;i<=foo;i++)
...
Run Code Online (Sandbox Code Playgroud)
哪一个更有效率?循环是进行一次计算还是每次迭代?
我创建一个数组let arr = new Array(99999),但我不填满它来arr.length是99999,我怎么能知道有多少实际的,非undefined元素我有此数组中?
有没有比寻找第一个更好的方法undefined?
我想从没有实例调用的静态函数调用内部函数,如下所示:
Foo.Bar = function (options) {
Autodesk.Viewing.Extension.call(this, options);
...
this.innerFunc = function innerFunc(){
...
}
};
Foo.Bar.prototype.constructor =
Foo.Bar;
Foo.Bar.SomeStaticFunc = function () {
innerFunc();
}
Run Code Online (Sandbox Code Playgroud)
使用:Foo.Bar.SomeStaticFunc();.
但我明白了SomeStaticFunc is not a function.
这里的例子使用了一个变量用于类,var Foo.Bar = function (options) {...但是不像创建类的实例那样并调用内部函数?
let x= new Foo.Bar(options);
x.innerFunc();
Run Code Online (Sandbox Code Playgroud)
还有另一种方法吗?
PS:我知道ES6课程,但我现在不想将这个课程迁移到ES6,因为它不是完全直截了当的.
我想std::find在一个shared_ptr抽象类的列表上使用,但我收到一个错误.有没有办法shared_ptr通过解除引用来比较两个std::find?
是否有可能让一个operator==超载的朋友shared_ptr<A>?
最小的例子:
#include "point.h"
#include <list>
#include <algorithm>
#include <memory>
using namespace std;
class A {
protected:
Point loc;
public:
virtual void foo() = 0;
virtual bool operator==(const Point& rhs) const = 0;
};
class B: public A {
virtual void foo() override{}
virtual bool operator==(const Point& rhs) const override {
return rhs == loc;
}
};
class C {
list<shared_ptr<A>> l;
void bar(Point & p) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试为四连胜(或连接四或连接四)游戏实现 MinMax 算法。
我想我明白了,它应该构建一棵可能的板树,达到一定的深度,评估它们并返回它们的分数,然后我们只取这些分数的最大值。
因此,aiChooseCol()通过调用检查每个可能列的分数MinMax()并返回具有最大分数的列。
现在我不确定这是正确的打电话方式吗MinMax()?
检查一下是否正确temp = Math.Max(temp, 1000);?
我还没有制作启发式函数,但这至少应该识别一个获胜列并选择它,但目前它只是选择左侧的第一个免费列......我不知道我做错了什么。
private int AiChooseCol()
{
int best = -1000;
int col=0;
for (int i = 0; i < m_Board.Cols; i++)
{
if (m_Board.CheckIfColHasRoom(i))
{
m_Board.FillSignInBoardAccordingToCol(i, m_Sign);
int t = MinMax(5, m_Board, board.GetOtherPlayerSign(m_Sign));
if (t > best)
{
best = t;
col = i;
}
m_Board.RemoveTopCoinFromCol(i);
}
}
return col;
}
private int MinMax(int Depth, board Board, char PlayerSign)
{
int temp=0;
if …Run Code Online (Sandbox Code Playgroud) 我想从类中调用其他类方法但是当一些方法调用一个方法时,我失去了访问权限,this因为现在this是调用方法而不能使用其他类方法或获取数据成员.
例如:
class someclass{
_this = this;
foo(){
this.bar();
}
bar(){
this.baz(); // this is foo not someclass
_this.baz(); // _this is not defined
}
baz(){
}
}
Run Code Online (Sandbox Code Playgroud)
那么我怎么能总是访问实际的类来调用它的方法并从其方法中使用它的数据成员呢?
编辑:在我的实际代码中,我有另一个foo使用事件调用的对象,因此this在进入时foo不是someclass.
我有一个元素排列成一行的 div,这是它的 css 类:
.myRow {
display: grid;
grid-template-columns: 0.1fr 0.1fr 2fr 3fr 2fr;
grid-column-gap: 10px;
grid-row-gap: 10px;
justify-content: center;
padding: 10px;
}Run Code Online (Sandbox Code Playgroud)
<div class="myRow">
<div style="color:blue; width: 5px;">aa</div>
<div style="color:red;">bb</div>
<div style="color:green;">ccc</div>
<div style="color:orange;">ddd</div>
<div style="color:purple;">eee</div>
</div>Run Code Online (Sandbox Code Playgroud)
我希望能够消除前两个间隙并保留其余间隙,就像grid-template-columns工作原理一样。
可以用网格来做到这一点吗?
编辑:我希望它是这样的:
我希望模态在点击它的外部时关闭,就像在示例中一样:https : //reactstrap.github.io/components/modals/但它没有发生:
https://codesandbox.io/s/x9rx5jx34q
按下按钮,然后单击其他任何地方,没有任何反应。我的代码中也会发生同样的情况。
我试图添加backdrop={true}为模态的道具,但没有用。
那么 reactstrap 在他们的例子中使用了什么?
javascript ×5
c++ ×2
ecmascript-6 ×2
es6-class ×2
reactjs ×2
android ×1
arrays ×1
c# ×1
c++11 ×1
css ×1
css-grid ×1
ecmascript-5 ×1
game-ai ×1
html ×1
minmax ×1
performance ×1
polymorphism ×1
react-native ×1
reactstrap ×1
runtime ×1
shared-ptr ×1
static ×1
syntax ×1