我正在尝试学习 emberjs,但偶然发现了计算属性部分示例中的错误(www.emberjs.com,“指南”部分中的“实际计算属性”示例)。当我从浏览器的控制台调用时,它总是显示错误“对象 [object Object] 的 Property 'fullName' is not a functionironMan.fullName()
” - 为什么?
我的代码是:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<script>
App = Ember.Application.create();
App.Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
var ironMan = App.Person.create({
firstName: "Tony",
lastName: "Stark"
});
</script>
同样在 jsbin 中:http: //jsbin.com/UnevOVU/3/edit