Java script prototype_hack
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
362
On Slideshare
361
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
2
Comments
0
Likes
2

Embeds 1

http://www.slideee.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JavaScript prototype & hack By Jax
  • 2. Overview • Object.prototype • Global Objects • DOM interfaces • EPS Hack Sample
  • 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. Sample 1 function MyClass(){}      MyClass.prototype.hello = function(){          console.log('hello 1');      }      var a = new MyClass();      a.hello(); 
  • 5. Sample 2 function MyClass(){}      var a = new MyClass();      MyClass.prototype.hello = function(){          console.log('hello 1');      }      a.hello(); 
  • 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. 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. Global Objects • • • • • • • • • • Object Function Boolean Number Math Date Array String RegExp ... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
  • 9. DOM interfaces • • • • • • • • • Element Event HTMLElement HTMLFrameElement HTMLFormElement HTMLTableElement HTMLTableRowElement HTMLTableCellElement ... https://developer.mozilla.org/en-US/docs/DOM/DOM_Reference
  • 10. 以 XMLHttpRequest 偽裝 ActiveXObject if (typeof (window.ActiveXObject) == "undefined" && window['XMLHttpRequest']) {       window.ActiveXObject = function () {          return new XMLHttpRequest();      };  } 
  • 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. 覆寫 getElementById document.org_getElementById = document.getElementById;  document.getElementById = function (id) {      var el = document.org_getElementById(id);      // ...      return el;  } 
  • 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. 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(); /* 遞迴呼叫 */  }