AMD&CMD
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script> ;(function(root, factory) { if (typeof module !== 'undefined' && module.exports) {// CommonJS module.exports = factory(); } else if (typeof define === 'function' && define.amd) {// AMD / RequireJS define(factory); } else { root.Promise = factory.call(root); } }(this, function() { 'use strict'; function PromiseA(resolver) { return this; } // new Promise().a() PromiseA.prototype.a = function () { console.log('a'); return this; }; PromiseA.prototype.b = function () { console.log('b'); return this; }; // Promise.a() PromiseA.a = function () { var p = new PromiseA(); return p.a(); }; PromiseA.b = function () { var p = new PromiseA(); return p.b(); }; return PromiseA; })); new Promise().a().b(); Promise.a().b(); </script> </body> </html>