请告诉我如何在coffeescript中写下面的javascript.
setTimeout(function(){
something(param);
}, 1000);
Run Code Online (Sandbox Code Playgroud) 是否有任何方法可以在Backbone.Controller中检测无效(或未定义)路由并触发404页面?
我已经在我的控制器中定义了这样的路由,但它没有用.
class MyController extends Backbone.Controller
routes:
"method_a": "methodA"
"method_b": "methodB"
"*undefined": "show404Error"
# when access to /#method_a
methodA: ->
console.log "this page exists"
# when access to /#method_b
methodB: ->
console.log "this also exists"
# when access to /#some_invalid_hash_fragment_for_malicious_attack
show404Error: ->
console.log "sorry, this page does not exist"
Run Code Online (Sandbox Code Playgroud)
我使用Backbone.Controller的构造函数来匹配当前的哈希片段和@routes.
class MyController extends Backbone.Controller
constructor: ->
super()
hash = window.location.hash.replace '#', ''
if hash
for k, v of @routes
if k is hash
return
@show404Error()
routes:
"method_a": "methodA"
"method_b": …Run Code Online (Sandbox Code Playgroud) 在为应用程序自动扩展我的EC2实例时,保持每个实例同步的最佳方法是什么?
例如,有下面的自定义设置和应用程序文件...
为了使我的自动缩放工作,所有这些必须在每个EC2实例中配置相同,并且我想知道同步这些元素的最佳实践.
我正在寻求一种干净的方法,将方法的返回值嵌入到类型/值的JSON编组中.如果我不需要编写自定义JSON marshaller,那就太好了.
例如,如果用户类型具有FirstName与LastName字段和FullName()方法,我怎样才能容易地嵌入一个full_name字段到JSON输出?
type User struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func (u User) FullName() string {
return fmt.Sprintf("%s %s", u.FirstName, u.LastName)
}
Run Code Online (Sandbox Code Playgroud)
预期的JSON:
{
"first_name": "John",
"last_name": "Smith",
"full_name": "John Smith"
}
Run Code Online (Sandbox Code Playgroud) 我如何得到struct的输出,按字段排序?
type T struct {
B int
A int
}
t := &T{B: 2, A: 1}
doSomething(t)
fmt.Println(t) // &{1 2} --> Sorted by fields
Run Code Online (Sandbox Code Playgroud) coffeescript ×2
go ×2
struct ×2
amazon-ec2 ×1
backbone.js ×1
javascript ×1
json ×1
marshalling ×1
replication ×1
settimeout ×1
sorting ×1