T
-TNO-
That's junk. If it works at all, its working is implementation-dependent.
Good god. I need to proof-read before I submit. My apologies indeed.
That's junk. If it works at all, its working is implementation-dependent.
-TNO- said:I posted this code as part of the question to the OP, to clarify what
he had in mind. I was "leading the witness" so to speak.
The keyword being "should", not "must".
Dmitry A. Soshnikov wrote:
...
Your insteresting comment inspired to study a little more these typing
matters,
and I made a little newbie script about duck typing
http://www.24.fi/optimistx/clj/ducktype.htm
Duck typing gives polymorfism without inheritance(?), according to wikipedia
wikipedia about duck typing
The above alert(1..toString) remains mysterious for me in spite
your explanations. Two dots! Never see earlier, and that seems to 'work'.
You should end all simple statements with a semicolon.
-TNO- wrote:
The keyword being "should", not "must".
...
Yes, that is a good list of information, to be used as a cheatsheet
every day!
"
Object Element
Element has the all the properties and methods of Node as well as the
properties and methods defined below.
The Element object has the following properties:
..."
But but... I do not see why and how I would need some complicated and
mysterious tricks with nodes and elements, wrestle with who would call
what and when and
pray that things turn out to work as I have imagined...
Element has all the properties of Node. So what? If I have a function
function useit(something){
if (typeof something.method1 !== 'undefined') something.method1();
} else {// ? }
and there something can be Node or Element or anything. One has
to check things there anyway (or has one?).
When we construct a Node or Element, we construct it, no complicated
inheritance
studies are needed, finding ancestors, cousins, grandmothers and phoning
them to ask permissions to tolk with their children or friends.( ok, a
bit exaggeration,
to create some artistic impression...).
John said:What on earth are you talking about ? To create an HTMLElement object
you just do
new HTMLElement(...)
where ... are the parameters, and Bingo!, an HTMLElement object
complete in all its glory. No more code to be added by you.
In this thread 'Useful classical inheritance example' I was interested to
find an example, where the page making person CREATES
a šuseful hierarcical inheritance pyramide
Prototype solely as a shared repository
of some functions is not advanced enough što earn the name 'inheritance'.
Dmitry said:[...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
<snip>In this thread 'Useful classical inheritance example' I was interested to
find an example, where the page making person CREATES
a useful hierarcical inheritance pyramide with his own javascript
code like the famous (but useless?!) example of Kevin Lindsay at
http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm
In the dom example we USE the structure made by others long time ago.
Dmitry said:Â [...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Dmitry said:Thomas said:JFTR: The better word to describe Python's inheritance mechanism is "net",Dmitry said:[...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Hardly.
By and large, classes in Python are also can be
called as *syntactic sugar*, 'cause in deed, we see the same
delegation to "prototypes" which could be changed dynamically at any
run-time.
P.S.> and coming back to multiple inheritance, in some realizations,
as some variant of imitation __noSuchMethod__ could be used: if object
(including its prototype chain) can't answer the message, than
catching __noSuchMethod__ we can make analysis of alternative
prototype chain (of some delegate, or, even - several delegate-objects)
Dmitry said:Thomas said:Dmitry A. Soshnikov wrote:
 [...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more thanone
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
It was essential enough to completely rewrite the MRO from Python 2.2 to
Python 2.3.
The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Hardly.
Everything can be called "syntactic sugar"
if you tune your
vocabulary enough.
Talk is cheap. Â Show me the code.
 -- Linus Torvalds
Dmitry said:Thomas said:It was essential enough to completely rewrite the MRO from Python 2.2 toDmitry said:Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
[...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
Python 2.3.
Hardly.The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Why so? Should i show an example? Or maybe you to me, where u'll
describe why "hardly"? It's interesting to me, really.
Talk is cheap. Show me the code.
-- Linus Torvalds
var object = {
delegates: [...],
addDelegate: function () {...},
__noSuchMethod__: function (name, args) {
alert([name, args]);
for (var k ... this.delegates ...) {
if (!(name in this.delegates[k])) {
continue;
}
return this.delegates[k][name].apply(this, args);
}
}
};
object.addDelegate({
test: function () {...},
...
});
object.addDelegate({
answerOtherMessage: function () {...},
...
});
object.test();
object.answerOtherMessage();
Dmitry said:Thomas said:Dmitry A. Soshnikov wrote:
Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
 [...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
It was essential enough to completely rewrite the MRO from Python 2.2 to
Python 2.3.
<http://www.python.org/download/releases/2.3/mro/>
The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Hardly.Why so? Should i show an example? Or maybe you to me, where u'll
describe why "hardly"? It's interesting to me, really.
Maybe later. Â Maybe elsewhere. Â Comparing programming languagesis not
on-topic here if not both are ECMAScript implementations.
var object = {Â delegates: [...],
 addDelegate: function () {...}, __noSuchMethod__: function (name, args) {
  alert([name, args]);
  for (var k ... this.delegates ...) {
   if (!(name in this.delegates[k])) {
    continue;
   }
   return this.delegates[k][name].apply(this, args);
  }
 }
object.addDelegate({
 test: function () {...},
 ...
});object.addDelegate({
 answerOtherMessage: function () {...},
 ...
});object.test();
object.answerOtherMessage();
Thanks. Â I had no doubt that the __noSuchMethod__() method could be written;
but your code avoids the issue by not answering to your premise: how do you
trigger it?
Dmitry said:Thomas said:Maybe later. Maybe elsewhere. Comparing programming languages is notDmitry said:Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
[...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
It was essential enough to completely rewrite the MRO from Python 2.2 to
Python 2.3.
<http://www.python.org/download/releases/2.3/mro/>
The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Hardly.
Why so? Should i show an example? Or maybe you to me, where u'll
describe why "hardly"? It's interesting to me, really.
on-topic here if not both are ECMAScript implementations.
Your choice, I do not insist. But that two things are different: (1)
you *don't wanna* comparing languages and see the general common
theory,
and (2) comparing languages is on topic
general theory but not only ECMA-262 technology
But if it will be interesting to you, i show you an example later.
__noSuchMethod__ is common office signal (message) which is caught
when object can't answer the message itself (including its prototype
chain). This signal is trigger *automatically* (did you try to run
this example?
try e.g. in SpiderMonkey and u'll see how it works).
It's general signal in general theory of dynamic objects and is in
some realizations: e.g.:
- #doesNotUnderstand (SmallTalk);
- method_missing (Ruby)
- __getattr__ (Python)
- __call (PHP)
- __noSuchMethod__ (some ECMAScript realizations, e.g. SpiderMonkey)
- and so on.
Sure it's not standard method, ECMA-262-3 says nothing about that,
that's why i mentioned that it's just theoretical academical interest
of that imitation
Dmitry said:Thomas said:Dmitry A. Soshnikov wrote:
Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
Thomas 'PointedEars' Lahn wrote:
Dmitry A. Soshnikov wrote:
 [...] Again, in ECMAScript there *is* inheritance - based on
delegation to prototypes. Try to find difference between Python's
class inheritance chain (it was not casually that i mentioned it above
and even showed full example).
JFTR: The better word to describe Python's inheritance mechanism is "net",
because it supports multiple inheritance -- inheritance from more than one
class.
<http://docs.python.org/tutorial/classes.html#multiple-inheritance>
Yeah, thx, i know about inheritance model used in Python. But,
multiple inheritance is just also additional code reuse *sugar* (yeah,
really, if we can reuse code from one class, why do not do that from
ten classes? - that's OK). It's not so essential.
It was essential enough to completely rewrite the MRO from Python 2.2 to
Python 2.3.
<http://www.python.org/download/releases/2.3/mro/>
The more essential is *mechanism of characteristic (properties/methods)
resolution* - which is very similar to ES delegation (with some
assumption, it can be treated the same).
Hardly.
Why so? Should i show an example? Or maybe you to me, where u'll
describe why "hardly"? It's interesting to me, really.
Maybe later. Â Maybe elsewhere. Â Comparing programming languages is not
on-topic here if not both are ECMAScript implementations.Your choice, I do not insist. But that two things are different: (1)
you *don't wanna* comparing languages and see the general common
theory,
What the heck are you talking about?
Not here, unless both languages are ECMAScript implementations.
(as we've mentioned
Your ignoring the topic of this newsgroup does not make these discussions
on-topic here.
(Cross-posted with Followup-To) elsewhere (comp.lang.misc), please.
It wasn't executable verbatim, so no(t yet).
Thanks for that, then.
Dmitry said:hey, take it easy, man it's just discussion, conversation. If
there's nothing to say, then don't say.
Are you too limited to see hardly further and deeper?
Why so? Sorry, who r u to send me to the .misc?
(Who are you, to post to a newsgroup in a chat style?)
well, now I am sending you to my
scorefile. Â Congratulations.
kangax said:I don't know exact semantics of `responds_to?` in Ruby or `__hasatr__`
in Python, but I have a feeling they don't care about value of a
property in question.
`in` operator would give a better indication of whether property is
present in object or its prototype chain.
`Object.prototype.hasOwnProperty` method would give a better indication
of whether property is present on an object itself.
Dmitry said:Dmitry A. Soshnikov wrote: [...]
http://www.24.fi/optimistx/clj/ducktype.htm
Duck typing gives polymorfism without inheritance(?), according to wikipedia
wikipedia about duck typingYep, thx for info, i know what is duck typing. It's actually related
to dynamic. The main goal is that the mutable object (with fully
possible mutations - not only value, but all characteristics) can pass
the test if it has all needed characteristics (properties/methods) *at
the moment*, which differs such mutable objects from static objects.// in static system (e.g. Java)
if (someObject instanceof someClass) {
 // some actions are allowed
}// in dynamic system, where object can
// mutates several times per life-cycle,
// it's not essential to which class (or type)
// object it related, the position in its
// hierarchy inheritance chain also is not
// essential ('cause again - object can totally
// mutates from one type to another), so the
// test-system is only interesting in that moment -
// if object "quacks" like it's needed? in more
// correct words - if object can *answer the message*
// (itself or by delegating to its prototype - no matter)?if (someObject.test) // ECMAScript
That's not a very good test for a *presence* of property
I don't know exact semantics of `responds_to?` in Ruby or `__hasatr__`
in Python, but I have a feeling they don't care about value of a
property in question.
`in` operator would give a better indication of whether property is
present in object or its prototype chain.
`Object.prototype.hasOwnProperty` method would give a better indication
of whether property is present on an object itself.
if someObject.respond_to?test) // Rubyif __hasatr__(someObject, 'test'): // Python
[...]
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.