On 01/04/12 15:08, Allen Wirfs-Brock wrote:
On Apr 1, 2012, at 8:07 AM, Quildreen Motta wrote:
How is the above better (ignoring any controversy about line-beginning
separators) than:
let ps = {
lookahead ( n) { this.current().slice(0, n || 1) },
current() { this.text.slice(this.offset) },
move(n) { this.clone(this.text, this.offset + 1) },
clone(text, offset) {
let r = Object.create(this);
r.offset = offset || 0;
r.text = text || '';
}
}
I forgot the object literal syntax was also getting a lightweight method
definition syntax, my bad.
You'd perhaps avoid some of the confusion on dynamic `this' by making
it explicit that `this' is just an additional parameter passed over
to the function — albeit implicitly.
"this" isn't just an additional parameter and trying to turn it into
such just creates more confusions. this (aka self) is a characteristic
feature of object-oriented /methods/, not of functions. Methods only
have meaning in the context of an object. It is essential to the OO
programming model that this/self is dynamically bounds to the object
that is the target of each method invocation. In a well designed OO
language the method invocation target is syntactically distinct from
"other parameters". If this didn't have special OO semantics there
would be no reason to have special syntax and semantics for
defining/accessing this within a function. However, in that case you
don't have a OO language, instead you have a functional language that
is used to provide a (low fidelity) simulation of OO constructs.
Hm, perhaps because of my mostly functional background — JS is the only
OO language I've actually spent much time learning, — I've always seen
methods as higher-order functions (target -> a... -> b), and the
`object.method()' invocation pattern as just coupling single dispatching
with a nice infix function invocation syntax.
Maybe I'm thinking more in terms of possible implementation details than
concepts, which I'm not as familiar with.
It seems to work for Python, though there `self' is bound at the
instantiation time.
I don't believe this is correct, if you mean object instantiation
time. You can view obj.meth in Python as a left-curry operation that
creates a new function where the first parameter of meth is pre-bound
to obj. This is why Python does not have issue 3 above.
Ah, yes, you're right. The currying is done at the lookup/dispatch time.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss