Re: representing URIs and literals

2013/11/4 Austin William Wright <aaa@bzfx.net>

>
> Yet this is what I do with 'rdf'. Try it yourself:
>
> > require('rdf').setBuiltins();
> > var a = 4;
> > a.datatype
> 'http://www.w3.org/2001/XMLSchema#integer'
> > a.nodeType()
> 'TypedLiteral'
> > (4.5).datatype
> 'http://www.w3.org/2001/XMLSchema#decimal'
> > "_:x".nodeType()
> 'BlankNode'
>
> Magic!
>
>
>> > This is far more powerful than merely encoding all literals as a string.
>>
>> If it were possible, yes. Ruby offers this; I think it’s really cool.
>>
>
> More magic, brought to you by the magic `valueOf` method:
>
> Number.prototype.tl = function(t) {
>   Object.defineProperty(this,'datatype', { writable: false, configurable :
> false, enumerable: false, value: t } );
>   return this;
> }
> > var x = (5).dt('http://www.w3.org/2001/XMLSchema#int');
> > x+2
> 7
> > x.datatype
> 'http://www.w3.org/2001/XMLSchema#int'
>
> ... kind of.
>
> > typeof x
> 'object'
> > ++x
> 6
> > typeof x
> 'number'
>

I think that monkey-patching Javascript core object is really really bad,
due to all the failures of previous libraries that have tried.
In fact, the Prototypejs (http://prototypejs.org/) library did that.
Prototypejs have lost the 'war' against jQuery.
The main issue is that we have only one JS scope. If we all monkey-patch
core object, we end up with a big mess and everything stop working.

So, don't do that. JS developers won't use your library, because they have
already been there.
We may disagree about that ;)

Cheers,

Matteo

Received on Tuesday, 5 November 2013 18:59:45 UTC