小编all*_*uis的帖子

面向对象的JavaScript编程

在开始尝试学习backbone.js之前,我一直在尝试用JavaScript学习OOP.

我希望能够数据绑定,但我似乎无法让它工作.

我刚刚制作了一个预算网站的简单原型,你可以把它放在一个预算中并输入你花了多少钱,它会显示你是否已经过去了.

function BudgetItem(spent, budget){

    this.setSpent = function(spent){
        this.spent = spent;
    }
    this.setBudget = function(budget){
        this.budget = budget;
    }
    this.getSpent = function(){
        return this.spent;
    }
    this.getBudget = function(){
        return this.budget;
    }

}

function BudgetType(type){
    this.getType = function(){
        return type;
    }
}

BudgetType.prototype = new BudgetItem();

$(document).ready(function(){

    var food = new BudgetType('food');

    $('.budget').html(food.getBudget());
    $('.editbudget').change(function(){
        food.setBudget($('.editbudget').data())
    });
})
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码.我不确定我做得对.我应该扩展一些东西吗?此外,有人可以解释如何动态数据绑定没有库吗?

javascript oop

4
推荐指数
1
解决办法
1135
查看次数

标签 统计

javascript ×1

oop ×1