Java script prototype_hack

550 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
550
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Java script prototype_hack

  1. 1. JavaScript prototype & hack By Jax
  2. 2. Overview • Object.prototype • Global Objects • DOM interfaces • EPS Hack Sample
  3. 3. Object.prototype All objects in JavaScript are descended from Object; all objects inherit methods and properties from Object.prototype, although they may be overridden (except an Object with a null prototype, i.e. Object.create(null)). For example, other constructors' prototypes override the constructor property and provide their own toString methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain. https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype
  4. 4. Sample 1 function MyClass(){}      MyClass.prototype.hello = function(){          console.log('hello 1');      }      var a = new MyClass();      a.hello(); 
  5. 5. Sample 2 function MyClass(){}      var a = new MyClass();      MyClass.prototype.hello = function(){          console.log('hello 1');      }      a.hello(); 
  6. 6. Sample 3 function MyClass(){}      MyClass.prototype.hello = function(){          console.log('hello 1');      }      var a = new MyClass();      var b = new MyClass();      a.hello = function(){          console.log('hello 2');      };      b.hello();
  7. 7. Class Inherit var Person = function() {          this.greet = function() {              console.log("Hi, I'm " + this.name);              };      };      var Customer = function(name) {          this.name = name;      };      Customer.prototype = new Person();      var joe = new Customer('Joe');      var mike = new Customer('Mike');      joe.greet();      mike.greet(); 
  8. 8. Global Objects • • • • • • • • • • Object Function Boolean Number Math Date Array String RegExp ... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
  9. 9. DOM interfaces • • • • • • • • • Element Event HTMLElement HTMLFrameElement HTMLFormElement HTMLTableElement HTMLTableRowElement HTMLTableCellElement ... https://developer.mozilla.org/en-US/docs/DOM/DOM_Reference
  10. 10. 以 XMLHttpRequest 偽裝 ActiveXObject if (typeof (window.ActiveXObject) == "undefined" && window['XMLHttpRequest']) {       window.ActiveXObject = function () {          return new XMLHttpRequest();      };  } 
  11. 11. 以 addEventListener 偽裝 attachEvent div.attachEvent(“onclick", function(){ }); if (typeof(window.attachEvent) == "undefined") {      window.attachEvent = function (event, pDisp) {          this.addEventListener(event.substr(2), pDisp, false);      };  } 
  12. 12. 覆寫 getElementById document.org_getElementById = document.getElementById;  document.getElementById = function (id) {      var el = document.org_getElementById(id);      // ...      return el;  } 
  13. 13. 修正 insertRow 在不帶參數時,並不是在最後加入的差 異 var oTable = document.getElementById("InventorItem"); var oRow = oTable.insertRow();    if (window['HTMLTableElement']) {      HTMLTableElement.prototype.org_insertRow = HTMLTableElement.prototype.insertRow;       HTMLTableElement.prototype.insertRow = function (index) {          if (!index) { index = this.rows.length; }          return this.org_insertRow(index);      };  } 
  14. 14. Resize Parent Iframe function parentResize() {      if(window.parent == window || !window.parent['_resizeIframe']){ return; }      window.parent._resizeIframe(window, $(document).width(), $(document).height());  }  function _resizeIframe (childWindow, width, height) {      var $iframe = $('iframe').filter(function(){          return this.contentWindow == childWindow;      });      $iframe.css({'width':width, 'height':height});      parentResize(); /* 遞迴呼叫 */  } 

×