- From: Ivan Herman <ivan@w3.org>
- Date: Thu, 13 Jan 2011 11:01:19 +0100
- To: nathan@webr3.org
- Cc: Manu Sporny <msporny@digitalbazaar.com>, RDFa WG <public-rdfa-wg@w3.org>, Tim Berners-Lee <timbl@w3.org>
- Message-Id: <33AC6D88-434D-4363-8A3B-B36BC3DBBB07@w3.org>
On Jan 13, 2011, at 10:38 , Nathan wrote: [snip] > >> I haven't tried this out, so there may be something preventing us from >> doing this in JavaScript, but basically, we'd change the PrefixMap >> interface from this: >> omittable getter DOMString get(in DOMString prefix); >> omittable setter void set(in DOMString prefix, in DOMString iri); >> to this (note the change in return type for get()): >> omittable getter PrefixResolver get(in DOMString prefix); >> omittable setter void set(in DOMString prefix, in DOMString iri); >> [Callback] >> interface PrefixResolver >> { >> DOMString resolve(in DOMString prefix); >> } > > sadly that's not possible, even with ECMAScript-262 v5 features, because of the setter, it would need to be a defined method such as setPrefix which would then define a magic property on the object to enable > > rdf.prefixes.foaf('name') > > However you'd need v5 advanced features and it's far from "normal" js behaviour. I was actually wondering about how this could be done in javascript. In Python, though not trivial, it is possibly to modify an objects __dict__, as it called there, ie, adding a new method to an object dynamically with any name created run-time... > > That said, in a previous revision of the api, there was another (disputed iirc) approach, which was to change the return type of Profile::setPrefix from void to a "PrefixResolver", so you'd: > > foaf = rdf.setPrefix('foaf', 'http://xmlns.com/foaf/0.1/'); > > then you could do: > > foaf('name') > rdf.resolve('foaf:name') > rdf.prefixes.foaf + name > ... This is actually very close to what I am used to, which is foaf = Namespace('http://xmlns.com/foaf/0.1/') although, for my instinct, the first argument ('foaf') is actually superfluous. But I can live with that... Ivan > > and you could still ignore this functionality and just do the getter/setter approach if you wanted: > > rdf.prefixes.foaf = 'http://xmlns.com/foaf/0.1/' > rdf.resolve('foaf:name') > rdf.prefixes.foaf + name > ... > > this is something of a happy medium which allows the compact functional style implemented in tabulator foaf('name'), and the current dictionary type approach. > > Best, > > Nathan ---- Ivan Herman, W3C Semantic Web Activity Lead Home: http://www.w3.org/People/Ivan/ mobile: +31-641044153 PGP Key: http://www.ivan-herman.net/pgpkey.html FOAF: http://www.ivan-herman.net/foaf.rdf
Attachments
- application/pkcs7-signature attachment: smime.p7s
Received on Thursday, 13 January 2011 10:04:57 UTC