将coffee脚本转换为简单的扩展
converting coffee script to simple extend
我有一些咖啡脚本-
class Zoo.CollectionView extends Zoo.View
_set_element_attributes: ->
@$el.data(view: this)
@$el.addClass('collection')
return unless @collection?
@$el.attr('data-name': @collection.collection_name)
@$el.attr('data-variant': @variant) if @variant?
@$el.data(collection: @collection, view: this)
我想转换为javascript并尽可能保持简单。我原以为这会奏效,但它似乎不喜欢我的扩展。
Zoo.CollectionView = function() {
}
$.extend(Zoo.CollectionView.prototype, Zoo.View.prototype);
Zoo.CollectionView.prototype._set_element_attributes = function() {
this.$el.data({
view: this
});
this.$el.addClass('collection');
if (this.collection == null) {
return;
}
this.$el.attr({
'data-name': this.collection.collection_name
});
if (this.variant != null) {
this.$el.attr({
'data-variant': this.variant
});
}
return this.$el.data({
collection: this.collection,
view: this
});
};
CoffeeScript的extends
与Backbone的extend
兼容,因此您应该能够做到这一点:
Zoo.CollectionView = Zoo.View.extend({
_set_element_attributes: function() {
// This part should be easy and it looks like you
// have it in hand.
}
});
我不明白你为什么要把Backbone.Model
的原型合并成Zoo.CollectionView
的:
$.extend(Zoo.CollectionView.prototype, Backbone.Model.prototype);
因为你的CoffeeScript不会做任何类似的事情,而且模型和视图无论如何都是非常不同的。
相关文章:
- 为内容脚本[Chrome扩展]获取本地存储价值的简单方法
- 开发Firefox扩展最简单的方法是什么
- 简单扩展原生JS
- 将coffee脚本转换为简单的扩展
- 简单的chrome重定向扩展
- 简单的一个?将变量从 Chrome 扩展程序页面传递到 PHP 页面
- 要发送/显示的简单 chrome 扩展程序网址
- 我如何获得这个非常简单的页面移植到Chrome扩展程序以在Firefox和Safari上运行
- 简单的谷歌浏览器扩展程序来检测网页上的点击 - 没有显示警报(错误)
- Chrome 扩展程序 - 用于在任何页面上运行 js 的简单内容脚本
- 将外部数据加载到chrome扩展程序的最简单方法是什么
- 简单的浏览器扩展程序,但存在问题
- 简单的高亮文本镀铬扩展名
- 有没有一种简单的方法可以扩展Coral UI js对象来添加自定义元素
- Javascript DOM Chrome扩展简单脚本
- 简单的JavaScript Chrome扩展-打开一个URL-从输入文本修改
- 简单的js注入带有chrome扩展的代码
- 简单firefox扩展“;不兼容”;《苍白的月亮》中的错误
- 如何向我的网站发送简单的消息'来自Chrome扩展的php
- 在Chrome扩展中打开和关闭一个简单的弹出窗口