[Prototype-core] Private methods for prototype class
Hi, I apologize if this question has been asked before. I've tried googling for this, but did find a good answer. What's the best way to have private methods using prototype's Class.create? I've tried... var Worker = Class.create((function() { function initialize() { this.someVar = var; privateMethod(); } function publicMethod() { privateMethod(); } function privateMethod() { console.info(this.someVar); console.info(this) } return { initialize: initialize }; })()); Running this will give me: console.info(this.someVar) #= undefined console.info(this.someVar) #= DOMWindow However: aWorker = new Worker(); aWorker.publicMethod() #= WORKS! Thank you for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Private methods for prototype class
opps, i had typo. return should be: return { initialize: initialize, publicMethod: publicMethod } On Sep 10, 9:37 am, Ngan nganp...@gmail.com wrote: Hi, I apologize if this question has been asked before. I've tried googling for this, but did find a good answer. What's the best way to have private methods using prototype's Class.create? I've tried... var Worker = Class.create((function() { function initialize() { this.someVar = var; privateMethod(); } function publicMethod() { privateMethod(); } function privateMethod() { console.info(this.someVar); console.info(this) } return { initialize: initialize }; })()); Running this will give me: console.info(this.someVar) #= undefined console.info(this.someVar) #= DOMWindow However: aWorker = new Worker(); aWorker.publicMethod() #= WORKS! Thank you for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Private methods for prototype class
Hi Ngan, This question is probably more appropriate for the user's group[1], rather than the core development group. If you'll repost over there, there are a couple of things to point out in that stuff... [1] http://groups.google.com/group/prototype-scriptaculous -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 10, 5:39 pm, Ngan nganp...@gmail.com wrote: opps, i had typo. return should be: return { initialize: initialize, publicMethod: publicMethod } On Sep 10, 9:37 am, Ngan nganp...@gmail.com wrote: Hi, I apologize if this question has been asked before. I've tried googling for this, but did find a good answer. What's the best way to have private methods using prototype's Class.create? I've tried... var Worker = Class.create((function() { function initialize() { this.someVar = var; privateMethod(); } function publicMethod() { privateMethod(); } function privateMethod() { console.info(this.someVar); console.info(this) } return { initialize: initialize }; })()); Running this will give me: console.info(this.someVar) #= undefined console.info(this.someVar) #= DOMWindow However: aWorker = new Worker(); aWorker.publicMethod() #= WORKS! Thank you for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Private methods for prototype class
Ah! thank you! sorry for the inconvenience! On Thu, Sep 10, 2009 at 10:04 AM, T.J. Crowder t...@crowdersoftware.comwrote: Hi Ngan, This question is probably more appropriate for the user's group[1], rather than the core development group. If you'll repost over there, there are a couple of things to point out in that stuff... [1] http://groups.google.com/group/prototype-scriptaculous -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 10, 5:39 pm, Ngan nganp...@gmail.com wrote: opps, i had typo. return should be: return { initialize: initialize, publicMethod: publicMethod } On Sep 10, 9:37 am, Ngan nganp...@gmail.com wrote: Hi, I apologize if this question has been asked before. I've tried googling for this, but did find a good answer. What's the best way to have private methods using prototype's Class.create? I've tried... var Worker = Class.create((function() { function initialize() { this.someVar = var; privateMethod(); } function publicMethod() { privateMethod(); } function privateMethod() { console.info(this.someVar); console.info(this) } return { initialize: initialize }; })()); Running this will give me: console.info(this.someVar) #= undefined console.info(this.someVar) #= DOMWindow However: aWorker = new Worker(); aWorker.publicMethod() #= WORKS! Thank you for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Private methods for prototype class
Hi, Ngan. Sorry you're having trouble. This mailing list is reserved for development purposes. Please direct assistance requests to http://groups.google.com/group/prototype-scriptaculous Thank you. Tobie --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] True Hashes using objects as keys
Core, Wanted to ask about why Hash doesn't support Objects as keys? I believe it relies on Javascript using the toString on the object to set the key's value, rather than a true hash. var key1 = new Object(); var key2 = new Object(); var h = $H(); h.set(key1, First); h.set(key2, Second); h.get(key1) // - Second Is there any plan to support true object-as-key ability? I couldn't find discussion on the topic searching the group. -- James Aimonetti mobile: 314.809.6307 work: 540.459.2220 email: james.aimone...@gmail.com website: http://jamesaimonetti.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Possible bug when adding additional element methods in IE8
actually, while creating the test, I started cutting unrelated parts from my included scripts, and once I removed my overwrite of the Element function (which was overwritten between the two method additions), the second set of methods were defined. My overwrite is this, in case anyone is interested in to why it was causing problems with IE8 and addMethods alone: if (Prototype.Browser.IE) (function() { var element = this.Element; this.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; if (Prototype.Browser.IE) { var attributeString = ''; for (var key in attributes) { if (typeof attributes[key] == 'string') { var name = key == 'className' ? 'class' : key == 'htmlFor' ? 'for' : key; attributeString += name + '=' + attributes[key] + ''; delete attributes[key]; } } tagName = '' + tagName + ' ' + attributeString + ''; return Element.writeAttribute(document.createElement(tagName), attributes); } if (!cache[tagName]) cache[tagName] = Element.extend (document.createElement(tagName)); return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; Object.extend(this.Element, element || { }); }).call(window); ^ the above is written to achieve this: new Element('div', {onclick:alert(1)}), or adding string callbacks when creating an element (which I need). I will just make this function exists in IE6 7, but not 8 for now, unless someone can tell me what exactly is causing this. If someone wants to, I can still attach a simple test for this. On Sep 10, 4:07 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi Viktor, Could you put together a small, self-contained test case that demonstrates what you're seeing and open a ticket in Lighthouse with it?[1] [1]http://prototypejs.org/contribute Thanks in advance, -- T.J. Crowder tj / crowder software / comwww.crowdersoftware.com On Sep 10, 11:56 am, Viktor Kojouharov vkojouha...@gmail.com wrote: Hello, I'm getting a rather weird error in IE8 specifically (not in IE7 or IE6). In two places I add additional element methods using Element.addMethods. The first time this is done, the added methods appear as Element.someMethod and $(element).someMethod. However, the second time additional methods are added, these methods appear only as Element.someMethod2. $(element).someMethod2 is undefined in that case. Not sure what's going on here, but as my code appears valid in all other browsers I tested it in (the other IEs, FF, Chrome), my guess is that there's something wrong with proto 1.6.1. In addition, I did not exhibit this behaviour with 1.6.0.3 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Possible bug when adding additional element methods in IE8
actually, looking at this further, I needed to add this line to my Element function: if (element) global.Element.prototype = element.prototype; it looks like it was added recently in prototype as well, maybe for IE8 specifically. On Sep 10, 9:09 pm, Viktor Kojouharov vkojouha...@gmail.com wrote: actually, while creating the test, I started cutting unrelated parts from my included scripts, and once I removed my overwrite of the Element function (which was overwritten between the two method additions), the second set of methods were defined. My overwrite is this, in case anyone is interested in to why it was causing problems with IE8 and addMethods alone: if (Prototype.Browser.IE) (function() { var element = this.Element; this.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; if (Prototype.Browser.IE) { var attributeString = ''; for (var key in attributes) { if (typeof attributes[key] == 'string') { var name = key == 'className' ? 'class' : key == 'htmlFor' ? 'for' : key; attributeString += name + '=' + attributes[key] + ''; delete attributes[key]; } } tagName = '' + tagName + ' ' + attributeString + ''; return Element.writeAttribute(document.createElement(tagName), attributes); } if (!cache[tagName]) cache[tagName] = Element.extend (document.createElement(tagName)); return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; Object.extend(this.Element, element || { }); }).call(window); ^ the above is written to achieve this: new Element('div', {onclick:alert(1)}), or adding string callbacks when creating an element (which I need). I will just make this function exists in IE6 7, but not 8 for now, unless someone can tell me what exactly is causing this. If someone wants to, I can still attach a simple test for this. On Sep 10, 4:07 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi Viktor, Could you put together a small, self-contained test case that demonstrates what you're seeing and open a ticket in Lighthouse with it?[1] [1]http://prototypejs.org/contribute Thanks in advance, -- T.J. Crowder tj / crowder software / comwww.crowdersoftware.com On Sep 10, 11:56 am, Viktor Kojouharov vkojouha...@gmail.com wrote: Hello, I'm getting a rather weird error in IE8 specifically (not in IE7 or IE6). In two places I add additional element methods using Element.addMethods. The first time this is done, the added methods appear as Element.someMethod and $(element).someMethod. However, the second time additional methods are added, these methods appear only as Element.someMethod2. $(element).someMethod2 is undefined in that case. Not sure what's going on here, but as my code appears valid in all other browsers I tested it in (the other IEs, FF, Chrome), my guess is that there's something wrong with proto 1.6.1. In addition, I did not exhibit this behaviour with 1.6.0.3 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: True Hashes using objects as keys
Hi James, You're right, Hash does indeed rely on underlying JavaScript vanilla objects, which can only use strings as keys. Supporting using objects as keys would be a complete rewrite, and a fairly inefficient one in terms of runtime performance (I did it once, and abandoned it as not worthwhile). I'm not aware of any plans to do so. I suspect you'd be better off (from a performance standpoint) building toString / fromString support into your keys. FWIW, -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 10, 7:07 pm, James Aimonetti james.aimone...@gmail.com wrote: Core, Wanted to ask about why Hash doesn't support Objects as keys? I believe it relies on Javascript using the toString on the object to set the key's value, rather than a true hash. var key1 = new Object(); var key2 = new Object(); var h = $H(); h.set(key1, First); h.set(key2, Second); h.get(key1) // - Second Is there any plan to support true object-as-key ability? I couldn't find discussion on the topic searching the group. -- James Aimonetti mobile: 314.809.6307 work: 540.459.2220 email: james.aimone...@gmail.com website:http://jamesaimonetti.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Possible bug when adding additional element methods in IE8
Hi, Prototype 1.6.1 is the first version to support IE8. Are you seeing this in the current release, or...? -- T.J. On Sep 10, 7:25 pm, Viktor Kojouharov vkojouha...@gmail.com wrote: actually, looking at this further, I needed to add this line to my Element function: if (element) global.Element.prototype = element.prototype; it looks like it was added recently in prototype as well, maybe for IE8 specifically. On Sep 10, 9:09 pm, Viktor Kojouharov vkojouha...@gmail.com wrote: actually, while creating the test, I started cutting unrelated parts from my included scripts, and once I removed my overwrite of the Element function (which was overwritten between the two method additions), the second set of methods were defined. My overwrite is this, in case anyone is interested in to why it was causing problems with IE8 and addMethods alone: if (Prototype.Browser.IE) (function() { var element = this.Element; this.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; if (Prototype.Browser.IE) { var attributeString = ''; for (var key in attributes) { if (typeof attributes[key] == 'string') { var name = key == 'className' ? 'class' : key == 'htmlFor' ? 'for' : key; attributeString += name + '=' + attributes[key] + ''; delete attributes[key]; } } tagName = '' + tagName + ' ' + attributeString + ''; return Element.writeAttribute(document.createElement(tagName), attributes); } if (!cache[tagName]) cache[tagName] = Element.extend (document.createElement(tagName)); return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; Object.extend(this.Element, element || { }); }).call(window); ^ the above is written to achieve this: new Element('div', {onclick:alert(1)}), or adding string callbacks when creating an element (which I need). I will just make this function exists in IE6 7, but not 8 for now, unless someone can tell me what exactly is causing this. If someone wants to, I can still attach a simple test for this. On Sep 10, 4:07 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi Viktor, Could you put together a small, self-contained test case that demonstrates what you're seeing and open a ticket in Lighthouse with it?[1] [1]http://prototypejs.org/contribute Thanks in advance, -- T.J. Crowder tj / crowder software / comwww.crowdersoftware.com On Sep 10, 11:56 am, Viktor Kojouharov vkojouha...@gmail.com wrote: Hello, I'm getting a rather weird error in IE8 specifically (not in IE7 or IE6). In two places I add additional element methods using Element.addMethods. The first time this is done, the added methods appear as Element.someMethod and $(element).someMethod. However, the second time additional methods are added, these methods appear only as Element.someMethod2. $(element).someMethod2 is undefined in that case. Not sure what's going on here, but as my code appears valid in all other browsers I tested it in (the other IEs, FF, Chrome), my guess is that there's something wrong with proto 1.6.1. In addition, I did not exhibit this behaviour with 1.6.0.3 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---