當創(chuàng)建模型實例時,類的構(gòu)造函數(shù)被調(diào)用,并且在創(chuàng)建模型時通過定義初始化函數(shù)來調(diào)用它。
new Model(attributes, options)
attributes:在創(chuàng)建模型的實例時,屬性定義模型的屬性。
options:這些是在創(chuàng)建模型時使用的屬性的id,name等選項。
<!DOCTYPE html>
<head>
<title> Model Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
<script type="text/javascript">
MyModel = Backbone.Model.extend({
initialize: function(){
document.write("Welcome to w3cschool..");
}
});
var mymodel = new MyModel;
</script>
</head>
<body></body>
</html>
Welcome to w3cschool..
更多建議: