小编Ada*_*sev的帖子

令人困惑的JavaScript语句:"var x = new this();"

我以为我理解了JavaScript原型对象的概念,以及[[proto]],直到我看到一些关于类继承的帖子.

首先,"JavaScript OOP - 智能方式",网址http://amix.dk/blog/viewEntry/19038

请参阅实施部分:

var parent = new this('no_init');
Run Code Online (Sandbox Code Playgroud)

还有John Resig的伟大博客上的"简单JavaScript继承".

var prototype = new this();
Run Code Online (Sandbox Code Playgroud)

究竟new this();是什么意思?

这句话对我没有意义,因为我的理解是this指向一个对象而不是构造函数.我也尝试在Firebug中测试语句来解决这个问题,我收到的只是语法错误.

我的头已经完全旋转了.

有人可以详细解释一下吗?

javascript inheritance class

16
推荐指数
3
解决办法
7818
查看次数

使用update_attribute运行Rails 3迁移时出现只读错误

我正在尝试添加一个counter_cache,这个Rails 3迁移给我一个我似乎无法解决的错误.

迁移是

class AddItemsCountToStore < ActiveRecord::Migration
    def self.up
        add_column :stores, :items_count, :integer, :default => 0

        Store.reset_column_information

        Store.all.each do |store|
            store.update_attribute :items_count, store.items.count
        end
    end

    def self.down
        remove_column :stores, :items_count
    end
end

而错误是:

== AddItemsCountToStore:迁移========================================= - add_column( :stores,:items_count,:integer,{:default => 0}) - > 0.0680s rake aborted!发生错误,此以及所有后续迁移都已取消:

items_count被标记为只读C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/persistence.rb:115:在`update_attribute"

有任何想法吗?

ruby-on-rails counter-cache update-attribute

13
推荐指数
0
解决办法
5754
查看次数