AMD&CMD

6164 단어
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Documenttitle>
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>

 
다음으로 전송:https://www.cnblogs.com/baie/p/4881541.html

좋은 웹페이지 즐겨찾기