Closed GoogleCodeExporter closed 8 years ago
> var f=base2.JSON.String.toJSONString;
> f.call(base2.JSON.String, "I said no!") == "I said no!"
> this.escape("I said no") == "I%20said%20no%21"
This is a coincidence really. Normally when you detach a JavaScript method it
doesn't
work at all. This works in a strange way because JSON.String and the global
object
both define an escape() method.
On a general note, and to answer your second question, Modules are static
objects
that just happen to be classes. All methods are static! That is why "this"
works for
static members. The prototype is built by delegating object methods to their
equivalent static method. That way, modules can act as mixins too.
See this for an example:
http://base2.googlecode.com/svn/trunk/src/base2/Module.txt
> BTW: can you create a "Type-Inquiry"
Will do. I'll also create Type-Discussion.
Original comment by dean.edw...@gmail.com
on 27 Jul 2007 at 9:19
I realized the coincidence.
I know how I can use Modules. I just haven't looked at the inner workings. Or
better: I opened the file, and 3
seconds later closed it again. I might open the file again, some other time ;-)
But, if you do:
var addClass=base2.DOM.HTMLElement.addClass;
addClass(document.body, "bold");
you get this error:
Value undefined (result of expression this.hasClass) is not object.
I just think some people are going to make this mistake, and will look in the
wrong places to solve this. Eventually,
they will see their mistake (and realize mixins are cool), or for the worse:
work around the mistake (and never
realize mixins are subzero). Either way: there's some cognitive disonance.
With other words: can we "fix" this non-technical usability error easy?
Original comment by doek...@gmail.com
on 27 Jul 2007 at 9:51
Are you saying that people will expect Module methods to be detachable like
this?
Original comment by dean.edw...@gmail.com
on 27 Jul 2007 at 10:26
In a way, I guess. Like I now know what I can do with Module doesn't mean I
fathom the complete concept. When I
encountered the issue, I didn't even realize base2.JSON.String *was* a Module.
And I also can imagine, people will not grasp the concept of Module enough, to
withhold them making this mistake
(made up innermind conversation of some developer: "hey, modules, cool. You can
apply them to classes, and use 'm
standalone. That's a lot of syntax. Let's create a shortcut variable"...).
But for my sake they don't need to be used detached. Can't we add some checks,
so an meaningful exception is thrown
when a module-method is used detached?
Original comment by doek...@gmail.com
on 27 Jul 2007 at 10:38
You know that all of base2.DOM is written as Modules? That's why you can do
this:
HTMLElement.addClass(element, "cool"); // as module
or:
HTMLElement(element); // as mixin
element.addClass("cooler");
you can also do this of course:
HTMLElement(element).addClass("cooler");
I'm not sure what to do about detaching Module methods. It would be a nice
feature. I
need to think about it for a bit...
Original comment by dean.edw...@gmail.com
on 27 Jul 2007 at 10:57
If you can address the issue with not too much trouble, it would be great.
The bigger issue is I think addressing layer leakage. Base2 adds new concepts
on top of javascript. But once and a
while, some javascript things leak though. We need to keep the leakage as low
as possible, and when inevitable,
provide a towel (a meaningful exception, documentation).
Original comment by doek...@gmail.com
on 27 Jul 2007 at 11:10
I'm closing this issue (the original bug was fixed long ago).
As to detachable module methods, raise another issue for this if you think it is
important.
Original comment by dean.edw...@gmail.com
on 10 Aug 2007 at 4:21
Original issue reported on code.google.com by
doek...@gmail.com
on 27 Jul 2007 at 8:14