1. //前面加;是防止跟其他js压缩时报错
    2. ;(function(global){
    3. //开启严格模式
    4. "use strict";
    5. //构造函数定义一个类 传参数
    6. function Scroll(el,options) {
    7. //some code
    8. };
    9. //原型上提供方法
    10. Scroll.prototype = {
    11. //定义方法
    12. show: function() {
    13. //some code
    14. }
    15. };
    16. if (typeof module !== 'undefined' && module.exports) { //兼容CommonJs规范
    17. module.exports = Scroll;
    18. }esle if (typeof define === 'function'){ //兼容AMD/CMD规范
    19. define(function () {
    20. return Scroll
    21. })
    22. }else { //注册全局变量,兼容直接使用script标签引入插件
    23. global.Scroll = Scroll;
    24. }
    25. })(this);
    1. var scroll = new Scroll("#demo",{});
    2. scroll.show();