整理JavaScript代码 [英] Organizing javascript code

查看:99
本文介绍了整理JavaScript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个javascript应用程序.通常,我要做的是制作不同的模块,并在$(document).ready();函数中获取用户输入或单击事件.这适用于小型应用程序.但是,当我遵循相同的模式时,我的意思是在$(document).ready();中获得单击事件,然后会变得混乱.

那我如何为一个庞大的应用程序组织此文件?

预先感谢

解决方案

我在该主题上找到的最好的资源是Addy Osmani的创作共用书, Scalable JavaScript Application Architecture 的一部分,使之适应经典的设计模式和现代的工作流程.

一旦达到了中等程度的复杂性,您就会受益于使用使用MVC架构模式的变体构建的框架. Backbone.js 是领先者,并且是一个微型框架,这意味着与其他对象相比,它的手工操作更少.其他受欢迎的选择是 Ember.js KnockoutJS .

扩展和样板也建立在这些框架上,以处理重复的任务,例如数据/模型绑定和脚手架.对于Backbone,请查看Derick Bailey的 Backbone.Marionette 解决方案

The single-best resource I've found on this subject is Addy Osmani's creative commons book, Patterns for Large-Scale JavaScript Application Architecture. It is based in part of Nicholas Zakas' Scalable JavaScript Application Architecture, adapting it to classic design patterns and a modern workflow.

Once you reach even a modest-level of complexity, you'll benefit from working with a framework built using a variation of the MVC architecture pattern. Backbone.js is the frontrunner and is a micro-framework, meaning it does less hand-holding than others. Other popular choices are Ember.js, KnockoutJS.

Extensions and boilerplates are also built on these frameworks to handle repetitive tasks such as data/model binding and scaffolding. For Backbone, check out Backbone.Marionette from Derick Bailey and Backbone Aura, a not-quite-ready-for-production adaptation of the Osmani/Zakas architectural model built using Backbone as its... well, backbone.

这篇关于整理JavaScript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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