Prototype error's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    Prototype error's

    i i tryed to explore jQuery because its build from prototypes so i made script like that
    [CODE=javascript]
    var TaderDOM = window.TaderDOM = window.$ = function(elemen t) {
    return new TaderDOM.fn.ini t(element);
    };

    TaderDOM.fn = {
    init: function(elemen t) {
    return document.getEle mentById(elemen t);
    },
    html: function() {
    return "working";
    }
    };
    TaderDOM.fn.ini t.prorotype = TaderDOM.fn;
    [/CODE]

    when i call $(element).html (); it should return me working but it don't why?
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    Originally posted by tader
    i i tryed to explore jQuery because its build from prototypes so i made script like that
    [CODE=javascript]
    var TaderDOM = window.TaderDOM = window.$ = function(elemen t) {
    return new TaderDOM.fn.ini t(element);
    };

    TaderDOM.fn = {
    init: function(elemen t) {
    return document.getEle mentById(elemen t);
    },
    html: function() {
    return "working";
    }
    };
    TaderDOM.fn.ini t.prorotype = TaderDOM.fn;
    [/CODE]

    when i call $(element).html (); it should return me working but it don't why?
    because new TaderDOM.fn.ini t(element) returns an object, the element.

    the html() function you want is one dot to the left, on TaderDOM.fn.
    other than being stored in the same object, init and html bear no inherit relation ship to each other.
    you are essentially just pointing to the function init as any other variable.

    you could add .html() to, say, Object's prototype (some will cringe), or create a constructor function, and add .html() to it's prototype.

    Comment

    • tader
      New Member
      • Sep 2007
      • 43

      #3
      so i did script like this and i has one problem when i call $(element) it don't returns the element how i should if i put return statement in init function all script brakes how to do that when i put return statement the script wouldn't broke
      [CODE=JavaScript]
      var TaderDOM = window.TaderDOM = window.$ = function(elemen t) { return new TaderDOM.fn.ini t(element); };

      TaderDOM.fn = {
      Object: new Object,
      init: function(elemen t) {
      TaderDOM.fn.Obj ect = document.getEle mentById(elemen t);
      },
      html: function() {
      return this.Object.inn erHTML;
      }
      };

      TaderDOM.fn.ini t.prototype = TaderDOM.fn;
      [/CODE]

      Comment

      Working...