是否可以在类上具有静态属性,该属性将作为一次性计算.我们的想法是能够这样做:
class Foo:
static_prop = Foo.one_off_static_method()
@staticmethod
def one_off_static_method():
return 'bar'
Run Code Online (Sandbox Code Playgroud)
我也想过使用__new__它.
Class Foo:
def __new__(cls):
cls.static_prop = ... do everything here
Run Code Online (Sandbox Code Playgroud)
虽然不确定这个含义.
鉴于这样一个类:
class MyObject {
private String id1;
private String id2;
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof MyObject)) {
return false;
}
MyObject other = (MyObject) o;
return id1.equals(other.id1) || id2.equals(other.id2);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,相等不依赖于两个字段匹配,两个字段都有效.什么是hashCode这个类的合适实现?
刚刚更新为ember v1.12.0-beta.1和ember-data v1.0.0-beta.16.我在模型中的字段上收到以下弃用警告:
DEPRECATION: Using the same function as getter and setter is deprecated. See http://emberjs.com/deprecations/v1.x/#toc_deprecate-using-the-same-function-as-getter-and-setter-in-computed-properties for more details.
Run Code Online (Sandbox Code Playgroud)
Ember检查员Deprecations视图指向我的所有模型.所以我的模型中每行基本上都有一个弃用错误.这是一个示例模型:
import DS from 'ember-data';
export default DS.Model.extend({
userid: DS.attr('number'),
unitid: DS.attr('number'),
log: DS.attr('string'),
name: DS.attr('string'),
start_date: DS.attr('date'),
end_date: DS.attr('date'),
duration_mins: DS.attr('number')
});
Run Code Online (Sandbox Code Playgroud)