<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      前端開發者進階之ECMAScript新特性【一】--Object.create

      Object.create(prototype, descriptors) :創建一個具有指定原型且可選擇性地包含指定屬性的對象

      參數:
      prototype 必需。  要用作原型的對象。 可以為 null。
      descriptors 可選。 包含一個或多個屬性描述符的 JavaScript 對象。
      “數據屬性”是可獲取且可設置值的屬性。 數據屬性描述符包含 value 特性,以及 writable、enumerable 和 configurable 特性。

      如果未指定最后三個特性,則它們默認為 false。 只要檢索或設置該值,“訪問器屬性”就會調用用戶提供的函數。 訪問器屬性描述符包含 set 特性和/或 get 特性。

      var pt = {
              say : function(){
                  console.log('saying!');    
              }
          }
          
          var o = Object.create(pt);
          
          console.log('say' in o); // true
          console.log(o.hasOwnProperty('say')); // false

      如果prototype傳入的是null,創建一個沒有原型鏈的空對象。

      var o1 = Object.create(null);
      console.dir(o1); // object[ No Properties ]

       當然,可以創建沒有原型鏈的但帶descriptors的對象;

      var o2 = Object.create(null, {
              size: {
                  value: "large",
                  enumerable: true
              },
              shape: {
                  value: "round",
                  enumerable: true
              }    
          });
          
          console.log(o2.size);    // large
          console.log(o2.shape);     // round
          console.log(Object.getPrototypeOf(o2));     // null

      也可以創建帶屬性帶原型鏈的對象:

      var pt = {
              say :
      function(){
                  console.log(
      'saying!');   
              }
          }

      var
      o3 = Object.create(pt, { size: { value: "large", enumerable: true }, shape: { value: "round", enumerable: true } }); console.log(o3.size); // large console.log(o3.shape); // round console.log(Object.getPrototypeOf(o3)); // {say:...}

       最重要的是實現繼承,看下面實例:

      //Shape - superclass
              function Shape() {
                this.x = 0;
                this.y = 0;
              }
              
              Shape.prototype.move = function(x, y) {
                  this.x += x;
                  this.y += y;
                  console.info("Shape moved.");
              };
              
              // Rectangle - subclass
              function Rectangle() {
                Shape.call(this); //call super constructor.
              }
              
              Rectangle.prototype = Object.create(Shape.prototype);
              
              var rect = new Rectangle();
      
              console.log(rect instanceof Rectangle); //true.
              console.log(rect instanceof Shape); //true.
              
              rect.move(); //"Shape moved."

       不支持瀏覽器的兼容實現:

      1、簡單實現,也是最常見的實現方式,沒有實現第二個參數的功能:

      if (!Object.create) {
          Object.create = function (o) {
              if (arguments.length > 1) {
                  throw new Error('Object.create implementation only accepts the first parameter.');
              }
              function F() {}
              F.prototype = o;
              return new F();
          };
      }

      2、復雜實現,實現第二個參數的大部分功能:

      if (!Object.create) {
      
          // Contributed by Brandon Benvie, October, 2012
          var createEmpty;
          var supportsProto = Object.prototype.__proto__ === null;
          if (supportsProto || typeof document == 'undefined') {
              createEmpty = function () {
                  return { "__proto__": null };
              };
          } else {
              createEmpty = function () {
                  var iframe = document.createElement('iframe');
                  var parent = document.body || document.documentElement;
                  iframe.style.display = 'none';
                  parent.appendChild(iframe);
                  iframe.src = 'javascript:';
                  var empty = iframe.contentWindow.Object.prototype;
                  parent.removeChild(iframe);
                  iframe = null;
                  delete empty.constructor;
                  delete empty.hasOwnProperty;
                  delete empty.propertyIsEnumerable;
                  delete empty.isPrototypeOf;
                  delete empty.toLocaleString;
                  delete empty.toString;
                  delete empty.valueOf;
                  empty.__proto__ = null;
      
                  function Empty() {}
                  Empty.prototype = empty;
                  // short-circuit future calls
                  createEmpty = function () {
                      return new Empty();
                  };
                  return new Empty();
              };
          }
      
          Object.create = function create(prototype, properties) {
      
              var object;
              function Type() {}  // An empty constructor.
      
              if (prototype === null) {
                  object = createEmpty();
              } else {
                  if (typeof prototype !== "object" && typeof prototype !== "function") {
      
                      throw new TypeError("Object prototype may only be an Object or null"); // same msg as Chrome
                  }
                  Type.prototype = prototype;
                  object = new Type();
      
                  object.__proto__ = prototype;
              }
      
              if (properties !== void 0) {
                  Object.defineProperties(object, properties);
              }
      
              return object;
          };
      }

      參考:

      https://developer.mozilla.org/zh-CN/docs/JavaScript/Reference/Global_Objects/Object/create

      https://developer.mozilla.org/zh-CN/docs/JavaScript/Reference/Global_Objects/Object/defineProperty

      https://developer.mozilla.org/zh-CN/docs/JavaScript/Reference/Global_Objects/Object/defineProperties

      https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create

      https://github.com/kriskowal/es5-shim/blob/master/es5-sham.js

      posted @ 2013-11-25 10:13  穆乙  閱讀(9712)  評論(1)    收藏  舉報
      主站蜘蛛池模板: 中国女人熟毛茸茸A毛片| 久久婷婷成人综合色综合| 日韩不卡无码精品一区高清视频| 国产一区二区视频在线看| 无码内射中文字幕岛国片| 九九热精品在线免费视频| 久久久av男人的天堂| 国产99在线 | 免费| 国产成人无码久久久精品一| 九色国产精品一区二区久久| 精品一区二区不卡免费| 激情亚洲内射一区二区三区| 四虎国产精品永久入口| 女人张开腿让男人桶爽| a4yy私人毛片| 欧美va亚洲va在线观看| 人妻少妇精品视频无码综合| 免费一区二区无码东京热| 日韩熟女精品一区二区三区| 男女爽爽无遮挡午夜视频| 亚洲偷自拍国综合| 国产精品久久久久鬼色| 精品一区二区不卡无码AV| 国产亚洲av夜间福利香蕉149| 麻豆av一区二区天美传媒| 色综合一本到久久亚洲91| 国内少妇偷人精品免费| 国产亚洲精品VA片在线播放 | 亚洲人成网站77777在线观看 | 男女啪祼交视频| 国产精品小一区二区三区| 免费无码成人AV片在线| 无码人妻一区二区三区四区AV| 日本一区二区a√成人片| 天天爽夜夜爱| 精品国产精品国产偷麻豆| 亚洲色大成网站WWW久久| 国产一区国产精品自拍| 国产999久久高清免费观看| 欧美videos粗暴| 亚洲精品国产综合久久一线|