Code Monkey home page Code Monkey logo

plugin-templates's Introduction

jQuery / Zepto 插件模板

jQuery/Zepto 都提供了很好的机制,让用户可以通过编写插件,来扩展功能。

很多人做了很久前端开发,却一直在使用别人的插件,自己没有完整开发过一个插件。其实开发插件不是很难的事情,经过多年,撰写一个 jQuery/Zepto 插件已经有了最佳实践,也就是所谓的基本的套路。这里给出基本的插件模板,让用户不用再考虑代码的组织,可以快速上手实现插件的编写,so easy! enjoy~

关于模板的详细信息,请参考模板中的注释。

jQuery / Zepto 插件开发注意事项

  • 用闭包保护全局变量不受污染
  • 插件尽量支持链式语法,可以通过 return this 实现;
  • 插件尽量对外暴露尽可能少的调用入口,比如:
    //推荐
    $.fn.myWindow("open");
    $.fn.myWindow("close");
    
    //不推荐
    $.fn.openMyWindow();
    $.fn.closeMyWindow();
  • 通过传入 options ,让插件可以定制,并提供默认的设置值
  • 尽量优化插件中冗余的代码
  • 不要试图提供繁多的配置项

更多内容请查阅 我的博客

plugin-templates's People

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.