我有下面的代码,但 javascript 似乎根本没有执行。
我在这里缺少什么吗?
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Backbonejs</title>
</head>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js">
<script type="text/javascript">
Person = Backbone.Model.extend({
initialize: function(){
console.log('hello world');
this.bind('change:name', function(){
console.log(this.get('name') + "is now the val for name");
});
},
defaults: {
name: "Bob hope",
height: "unknown"
},
validate: function(attributes){
if(attributes.name == "Joe"){
return "Uh oh, you're name is Joe!";
}
}
});
var person = new Person();
person.set({name: "Joe", height: "6 feet"});
</script>
</body>
</html>