考虑以下超类和扩展它的子类:
class SuperClass {
constructor(name){
this.name = name;
}
sayName = () => {
alert(this.name);
}
}
class SubClass extends SuperClass {
constructor(name){
super(name);
}
sayName = () => {
super.sayName();
document.getElementsByTagName('body')[0].innerHTML = this.name;
}
}
let B = new SubClass('Noam Chomsky');
B.sayName();
Run Code Online (Sandbox Code Playgroud)
在此示例中,该函数sayName在两个类定义中都被编写为箭头函数。当我打电话时,B.sayName()我收到一条错误消息:
函数或类之外的“超级”
JSFiddle 演示错误(检查控制台)
但是,如果我重写类定义以不使用箭头函数,则一切正常并且不会收到错误:
class SuperClass {
constructor(name){
this.name = name;
}
sayName() {
alert(this.name);
}
}
class SubClass extends SuperClass {
constructor(name){
super(name);
}
sayName() {
super.sayName();
document.getElementsByTagName('body')[0].innerHTML = this.name; …Run Code Online (Sandbox Code Playgroud) 假设我有一个组件接口,它应该扩展标准<div>元素的接口。写这个有什么区别:
interface ComponentProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> { ... }
Run Code Online (Sandbox Code Playgroud)
与此相反:
interface ComponentProps extends React.HTMLAttributes<HTMLDivElement> { ... }
Run Code Online (Sandbox Code Playgroud) 鉴于这些类型:
export type ButtonProps = {
kind?: 'normal' | 'flat' | 'primary';
negative?: boolean;
size?: 'small' | 'big';
spinner?: boolean;
}
export type LinkButtonPropsExtended = ButtonProps & React.HTMLProps<HTMLAnchorElement>;
const LinkButton = ({ children, href, ...rest }: LinkButtonPropsExtended) => (
<a href={href} className={cls(rest)}>
{ children }
</a>
);
Run Code Online (Sandbox Code Playgroud)
为什么会出现这个用例:
<LinkButton href={url} size="big">My button</LinkButton>
Run Code Online (Sandbox Code Playgroud)
抛出此类型错误:
export type ButtonProps = {
kind?: 'normal' | 'flat' | 'primary';
negative?: boolean;
size?: 'small' | 'big';
spinner?: boolean;
}
export type LinkButtonPropsExtended = ButtonProps & React.HTMLProps<HTMLAnchorElement>; …Run Code Online (Sandbox Code Playgroud) 我有这个按钮组件:
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
small?: boolean;
}
class Button extends React.Component<ButtonProps> { ... }
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这样做时:
<Button type="submit"></Button>
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{children?: ReactNode;”上不存在属性“type” }>'
为什么?属性不是type的一部分吗React.HTMLAttributes<HTMLButtonElement>?设置此属性的正确/推荐方法是什么?
在Supertest 的(非常有限的)文档中,有一些代码示例,其中done()传递了调用的回调函数:
describe('GET /user', function() {
it('responds with json', function(done) {
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
});
Run Code Online (Sandbox Code Playgroud)
此回调的目的/性质是什么done()?
我有一个大的div,里面有一个较小的div.较小的div首先显示为隐藏.当用户将鼠标悬停在大容器div上时,较小的div将使用show/hide-functions进行动画处理.到目前为止一切正常.
然而.较小的div从底部开始动画 - 所以如果我让光标悬停在最底部的容器上,当它滑入时,它会悬停在较小div的动画上.所以现在光标悬停在较小的div上更大的div,从而触发较小的div上的隐藏功能.这会创建一个无限循环的显示/隐藏调用,因为较小的div滑入和滑出光标指向的位置.
任何想法如何避免这种情况,并且不会在较小的div进入时打破容器上的悬停?
这就是我的意思:
alt text http://archivedworks.com/fileserver/jQuery_hover_showhide.jpg
我无法将 SVG 路径扩展到其容器:
<svg xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid"
viewBox="0 0 16 16"
width="16"
height="16">
<path stroke="#000" fill="none" d="M209,15a195,195 0 1,0 2,0zm1,0v390m195-195H15M59,90a260,260 0 0,0 302,0 m0,240 a260,260 0 0,0-302,0M195,20a250,250 0 0,0 0,382 m30,0 a250,250 0 0,0 0-382"></path>
</svg>
Run Code Online (Sandbox Code Playgroud)
演示: http: //jsfiddle.net/FeTv2/1/ - 正如您所看到的,路径太大,并且似乎有顶部和左侧偏移。
在 Chrome 和 Firefox 中看起来是一样的。
我在C中编写一个带有两个参数的小应用程序.一个是文件名,另一个是数字,它们可以按随机顺序指定.
./main filename 12345
和
./main 12345文件名
应该都有效.
当我知道文件名以字符开头时,我怎样才能轻松确定哪个是哪个?
reactjs ×3
typescript ×3
html ×2
javascript ×2
argv ×1
c ×1
ecmascript-6 ×1
hover ×1
jquery ×1
jquery-ui ×1
node.js ×1
parameters ×1
string ×1
supertest ×1
svg ×1