Backbone.js 真的是 MVC 吗? [英] Is Backbone.js really an MVC?

查看:27
本文介绍了Backbone.js 真的是 MVC 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

backbone.js 被称为 Javascript 的 MVC 框架.但是是吗?

这里是模型的描述,来自http://documentcloud.github.com/backbone/

<块引用>

模型是任何 JavaScript 应用程序的核心,包含交互式数据以及围绕它的大部分逻辑:转换、验证、计算属性和访问控制.你使用特定于领域的方法扩展 Backbone.Model 和 Model提供一组用于管理变更的基本功能.

现在,这完全不是我对 MVC 模型的理解.在我的理解中,模型只是为域建模的类,所以你的学生、学校和教师对象.控制器确实对它们执行业务逻辑,并与视图交互以显示和接收输入.

这个理解和我在网上找到的各种定义一致,IE http://en.wikipedia.org/wiki/Model_view_controller:

<块引用>

Model–View–Controller (MVC) 是一种针对计算机用户的设计模式将应用程序划分为三个区域的接口责任:

模型:域对象或数据结构表示应用程序的状态.

所以,我的问题是:backbone.js 是否真的是一个 MVC 框架,或者它更像是一种帮助您将所有东西粘合在一起的通用方法?

顺便说一下,backbone.js 的 FAQ 中模型的定义似乎与我上面引用的不同(同样来自于backbone.js http://documentcloud.github.com/backbone/#FAQ-mvc:

<块引用>

Backbone.Model – 就像 Rails 模型减去类方法.在业务逻辑中包装一行数据.

那么从什么意义上讲,backbone.js 到底是不是 MVC?

(警告:我目前只是在评估backbone.js.)

解决方案

当您试图找到M"(模型)V"(视图)和C"(控制器).

那样,我们总是可以就条款进行争论,但重要的是意图.

条款"与意图"相交:

M":

主干模型.集合模型相关联.

V":

默认的 Underscore.js 模板代表标准 MVC

查看意图"

C":

Backbone ViewController.它在主干中被称为 View(就像在许多其他像 Django 中一样),因为它处理渲染.从 MVC 的角度来看,它是一个控制器.路线视图

相关

现在,有时只是为了满足 MVC 的缩写,有些人将其称为模型视图集合".但那是不应该说的.

backbone.js has been spoken of as an MVC framework for Javascript. But is it?

Here is the description of the model, from http://documentcloud.github.com/backbone/

Models are the heart of any JavaScript application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control. You extend Backbone.Model with your domain-specific methods, and Model provides a basic set of functionality for managing changes.

Now, that is not my understanding of the model in MVC at all. In my understanding, the model is just the classes that model the domain, so your Student, School and Teacher objects. The controller does performs the business logic on them and interacts with the view for display and receiving input.

This understanding is consistent with the various definitions I find on the web, IE http://en.wikipedia.org/wiki/Model_view_controller:

Model–View–Controller (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility:

the Model: the domain objects or data structures that represent the application's state.

So, my question is: is backbone.js really a MVC framework in any sense, or is it more of just a general way of helping you to glue everything together?

Incidentally, the definition of the Model from backbone.js's FAQ appears to differ from the one I quoted above (also from backbone.js http://documentcloud.github.com/backbone/#FAQ-mvc:

Backbone.Model – Like a Rails model minus the class methods. Wraps a row of data in business logic.

So in what sense is backbone.js really an MVC or not?

(Caveat: I am just evaluating backbone.js currently.)

解决方案

Its a bit confusing when you try to find the "M" (Model) the "V" (View) and the "C" (Controller).

In that way we can always argue on the terms but what's important is the intend.

Intersecting the "Terms" with the "Intend" :

The "M" :

Backbone Models. The Collections are tied to Models.

The "V" :

The default Underscore.js template represents the "View Intention" of standard MVC

The "C" :

Backbone View is the Controller. Its called View in backbone (like in many others like Django) because it handles the rendering. From MVC point of view its a Controller. Routes are tied with the Views

Now, sometimes just to satisfy the MVC abbreviation some call it "Model View Collections". But that is what should not be said.

这篇关于Backbone.js 真的是 MVC 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆