By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Prototype error's

P: 43
i i tryed to explore jQuery because its build from prototypes so i made script like that
Expand|Select|Wrap|Line Numbers
  1. var TaderDOM = window.TaderDOM = window.$ = function(element) { 
  2.     return new TaderDOM.fn.init(element); 
  3. };
  4.  
  5. TaderDOM.fn = {
  6.     init: function(element) { 
  7.         return document.getElementById(element); 
  8.     },
  9.     html: function() {
  10.         return "working";
  11.     }
  12. };
  13. TaderDOM.fn.init.prorotype = TaderDOM.fn;
  14.  
when i call $(element).html(); it should return me working but it don't why?
Jun 13 '08 #1
Share this Question
Share on Google+
2 Replies


rnd me
Expert 100+
P: 427
i i tryed to explore jQuery because its build from prototypes so i made script like that
Expand|Select|Wrap|Line Numbers
  1. var TaderDOM = window.TaderDOM = window.$ = function(element) { 
  2.     return new TaderDOM.fn.init(element); 
  3. };
  4.  
  5. TaderDOM.fn = {
  6.     init: function(element) { 
  7.         return document.getElementById(element); 
  8.     },
  9.     html: function() {
  10.         return "working";
  11.     }
  12. };
  13. TaderDOM.fn.init.prorotype = TaderDOM.fn;
  14.  
when i call $(element).html(); it should return me working but it don't why?
because new TaderDOM.fn.init(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.
Jun 14 '08 #2

P: 43
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
Expand|Select|Wrap|Line Numbers
  1. var TaderDOM = window.TaderDOM = window.$ = function(element) { return new TaderDOM.fn.init(element); };
  2.  
  3. TaderDOM.fn = {
  4.     Object: new Object,
  5.     init: function(element) { 
  6.         TaderDOM.fn.Object = document.getElementById(element);
  7.     },
  8.     html: function() {
  9.         return this.Object.innerHTML;    
  10.     }
  11. };
  12.  
  13. TaderDOM.fn.init.prototype = TaderDOM.fn;
  14.  
Jun 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.