Coder Social home page Coder Social logo

requirejs-seed's Introduction

js规范

目录组织

└─public
    ├─images
    ├─js //自己写代码的地方
    ├─lib //第三方包存放的地方
      ├─jquery 
      ├─jquery-base64  (https://github.com/carlo/jquery-base64)
      ├─jquery-cookie  (https://github.com/huya-fed/jquery-cookie)
      ├─jquery-dateFormat (https://github.com/phstc/jquery-dateFormat)
      ├─jquery-MD5 (https://github.com/placemarker/jQuery-MD5)
      ├─layer (http://layer.layui.com/)
      ├─layerMobile (http://layer.layui.com/mobile/)
      ├─lazyload (https://github.com/jieyou/lazyload)图片懒加载的
      ├─require-css (用于加载css的require插件)
      ├─requirejs
      ├─swiper
      └─xarch
    └─styles //自己写css的地方

阅读文章:

** 1.必需要读: **

Javascript模块化编程(一):模块的写法

Javascript模块化编程(二):AMD规范

Javascript模块化编程(三):require.js的用法

前后端数据交互的几种方法

** 2.选择阅读: **

模块化编程 , 理解requireJS-实现一个简单的模块加载器

如何写一个Jquery插件

JQuery最佳实践

移动前端开发经验指南

JQuery常用插件

如何使用Google

代码抒写

** 1. 使用AMD规范组织代码 **

  define(['myLib'], function(myLib){
    function foo(){
      myLib.doSomething();
    }
    return {
      foo : foo
    };
  });

** 2. 代表jQuery对象的变量前面可以加个$,这样一眼就能看出来是个jQuery对象。 **

var $dom = $("#dom");

** 3.函数参数大于3个的时候,应该使用对象封装起来(避免修改参数而导致函数参数乱序) **

var myfn = function(opts){

	opts && console.info(opts.a);//输出a参数

	opts && console.info(opts.b);//输出b参数

	opts && console.info(opts.c);//输出c参数
}

** 4. JS里声明变量必须加上 var 关键字 **

** 5. JS代码结尾统一约定加';' **

** 6. JSON对象的最后一个字段、数组最后一个元素后面都不能加',',在IE8下会报错:所以{a:1,b:2,}/[1,2,] 都是不对的. **

** 7. JS模块里面私有的方法前面可以加_,公有方法不加,但是函数内的局部变量就没必要加_了; **

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.