从父类调用子方法是好/坏的做法?
class Parent {
constructor() {
// if 'autoPlay' exists (was implemented) in chain
if (this.autoPlay) {
this.autoPlay(); // execute from parent
}
}
}
class ChildA extends Parent {
autoPlay() {
console.log('Child');
}
}
class ChildB extends Parent {
// 'autoPlay' wasn't implemented
}
const childA = new ChildA();
const childB = new ChildB();
Run Code Online (Sandbox Code Playgroud) 我面临着获取id包含特殊字符.和$符号的元素的值的问题.
我对元素的id是"XS_19MAY2016_012720_311.04$_cal"我使用jQuery的语法:
$("#"+xyz+"_cal").val() where xyz is variable having above id.
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
Error: Syntax error, unrecognized expression: #XS_19MAY2016_012720_311.04$_cal.
Run Code Online (Sandbox Code Playgroud)
我做错了什么或我需要做些什么来纠正它.
在内部导入(使用)go 模块的正确方法是什么?
例如:
通过以下方式创建新模块:go mod init example.com/my-project(example.com 或其他不存在的域)
并在同一个项目中使用它:
import (
"example.com/my-project/package"
)
Run Code Online (Sandbox Code Playgroud)
此示例取自Let's Go书(但极其简化)
问题:
我正在使用 Goland,它无法识别此本地模块。Goland 建议我使用go get -t example.com/my-project/package命令。但example.com/...只是一个模块的名称
Go 1.13为错误引入了新功能,以简化错误处理。在Go 1.13之前,我通过以下方式检查代码是否存在错误:
if err == nil {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但是Go errors.Is()可以帮助我正确地做到这一点:
这是一种明智的方式,可用于将来对代码进行过时验证,并防止由您(或代码导入的任何程序包)引起的问题在将来包装错误。
对于这种情况,这是可以的:
if errors.Is(err, sql.ErrNoRows) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着我必须将所有err == nil声明更改为:
if errors.Is(err, nil) {
// ...
}
Run Code Online (Sandbox Code Playgroud) 我正在ES6上阅读Web上的教程,我很确定我读到有一种使用ES6调用REST Web服务的本地方法.
现在我正在搜索该主题,我找不到它.
所以在ES6中,我还需要像jquery/lodash等库来进行Web服务调用吗?或者我可以仅使用新的语言结构进行此类调用?
对不起,如果这是FAQ.如果问题很常见,我会删除这个问题......但我真的尝试过搜索,什么也没找到.但我非常确定我在某处读到了现在我们可以直接调用REST端点而无需任何外部库.
一个资源可以有多少个子集合?
想象一下我们有这个模型:账户 -> 帖子 -> 评论
帐户-帖子对的一切都很清楚。/accounts/{account_id}/posts/{post_id}
但是评论呢?指向单个评论的正确方法是什么?
/posts/{post_id}/comments/{comment_id}
或者
/accounts/{account_id}/posts/{post_id}/comments/{comment_id}
或(直接指向)
评论/{comment_id}
用 解析 uint64 最大值时这是正常行为strconv.ParseInt吗?
i, err := strconv.ParseInt("18446744073709551615", 10, 64)
fmt.Println(i, err)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:"strconv.ParseInt: parsing "18446744073709551615": value out of range"当 uint64 的最大允许值为:18446744073709551615
你能解释这种行为吗?
go ×3
javascript ×3
ecmascript-6 ×2
angularjs ×1
api ×1
collections ×1
go-modules ×1
goland ×1
html ×1
import ×1
jquery ×1
resources ×1
rest ×1
uint64 ×1
vgo ×1