Prev: How to link CSS(s) already linked to parent frame into child iframe using javascript
Next: Error getElementbyClassName
From: David Mark on 13 Jan 2010 08:24 Dmitry A. Soshnikov wrote: > On Jan 13, 3:05 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> > wrote: > >> Yes, it has. "In computer science, polymorphism is a programming language >> feature that allows values of different data types to be handled using a >> uniform interface. [...]" (en.Wikipedia) >> > > Polymorphism regarding to ECMAScript is related to several things. > > And about polymorphism - ECMAScript is polymorphic in several > meanings: > > 1. e.g. function could be applied to some objects as it's own method > of that objects: > > function test() { > alert([this.a, this.b]); > } > > test.call({a: 10, b: 20}); // 10, 20 > test.call({a: 100, b: 200}); // 100, 200 > > var a = 1; > var b = 2; > > test(); // 1, 2 > > Or, so called, *parametric polymorphism*, when function is one for all > types, but accepts mutable functional argument (Funarg). As example: > `sort method of arrays - it accepts sort-function, but `sort' method > itself - is common (one interface (.sort-method), several > implementations (sort-functions) - polymorphism, and `sort' method is > polymorphic). > > Or, regarding to duck (weak) typing (DT), - DT - is also kind of > polymorphism, as it's doesn't matter *what type* is object, but > important whether it able to handle some activity. Again - common one > interface of an object is essential, and there can be several > implementations of it - again polymorphism. > > So, it's not only about method overloading. > >> You don't know what you are talking about, or you are unable to read and >> understand English. Probably both. >> > > Demagogy. You really like that word. > >> Idiot. >> > > Would you mind if I suggest to filter your words before posting? > >> /* JScript .NET has `super' to refer to the superclass */ >> super.foo(); > > By the way, there's also one more ability to call overwritten parent > method just with `this._super()' expression. I assume you mean this._super.foo() to call the "super" foo method. > One (old) I've already > shown and it's well-know - to make special wrappers for that (by the > performance it's less efficient then using `constructor.superclass', > but from the elegant code - is). You would replace one line like the above with a wrapper? How would that make the code more elegant?
From: Thomas 'PointedEars' Lahn on 13 Jan 2010 08:25 Jorge wrote: > Thomas 'PointedEars' Lahn wrote: >> (...) >> Anyhow, now try that in a prototype method -- it will not work, because >> `this' refers to the calling object, not its prototype. And if you are >> still not convinced that this approach is not a general good solution, >> pray call the foo() method of the second-next object in the prototype >> chain now (again, without referring to prototype objects or constructors, >> per your claim.) > > Sorry, as for today, I've run out of tricks. You're such a coward, Jorge. Why don't you simply admit that you can't do it without referring to a prototype object or constructor because it can't be done? PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
From: Thomas 'PointedEars' Lahn on 13 Jan 2010 08:30 David Mark wrote: > Thomas 'PointedEars' Lahn wrote: >> Jorge wrote: >>> Jorge wrote: >>>> Thomas 'PointedEars' Lahn wrote: >>>>> (...) >>>>> o.foo = function() { >>>>> /* >>>>> * Pray call C.prototype.foo() here without referring >>>>> * to the constructor or the prototype object >>>>> */ >>>> //Pay close attention, Pointy: >>>> >>>> var save= this.foo; >>>> delete this.foo(); >>>> this.foo(); >>>> this.foo= save; >>> s/delete this.foo()/delete this.foo; >> >> It is a possibility, although it remains to be seen whether it is more >> efficient than simply calling the prototype's method.] > > Certainly it is not as efficient. A call plus a delete, plus a couple > of assignments and an extra variable? No way that's faster than a call > (even with one extra dot operation). ;) It is not just one extra dot operation; you have to consider the `this' value. So you need __proto__.foo.call(this) or an equivalent, where I suspect the greater penalty. Efficiency-wise only, of course. >> Given the possibility of setters and getters, it is certainly more >> error-prone than the direct approach already. > > It's just a God-awful example. I'm sure Crockford doesn't advocate > actually using it. I don't even think Jorge is that crazy. I think it makes for an interesting lesson, though. After all, if there was not the bad code, how could we recognize the good one? ;-) >> Anyhow, now try that in a prototype method -- it will not work, because >> `this' refers to the calling object, not its prototype. > > Yes, you would have to do the switcheroo on the prototype in that case. > I thought that was the variation he was going to post. Certainly > neither is a Good Part. :) ACK. I am surprised why Jorge of all people would go at lengths to prove Crockford wrong :) PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16
From: wmc on 13 Jan 2010 08:34 David Mark wrote: > On Jan 11, 10:01 am, wmc <...> wrote: >> I'm currently reading a JS book (Zakas, Prof. JavaScript for Web >> Developers, 2nd. Ed.) > > Do not waste money on browser scripting books by Zakas. He's been > proven clueless about the subject as recently as a week ago. ;) Too late, already bought a copy... My local library system has Zakas, the latest Definitive Guide (I own v4), JavaScript: The Good Parts, and John Resig's 'Pro JavaScript Techniques' so I was at least able to test drive it first. --williamc
From: Thomas 'PointedEars' Lahn on 13 Jan 2010 08:36
Dmitry A. Soshnikov wrote: > Thomas 'PointedEars' Lahn wrote: >> /* JScript .NET has `super' to refer to the superclass */ >> super.foo(); > > By the way, there's also one more ability to call overwritten parent > method just with `this._super()' expression. Tell me something I don't know yet (check out Function.prototype.extend() in object.js). Regardless, the *user-defined* `_super' property would be a reference to the constructor or prototype object (here: the prototype object), explicitly "prohibited" per Jorge's claim. Pay more attention. PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk> |