Coder Social home page Coder Social logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
> 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 [email protected] on 27 Jul 2007 at 9:19

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
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 [email protected] on 27 Jul 2007 at 9:51

  • Changed state: Started
  • Added labels: Type-Discuss
  • Removed labels: Type-Inquiry

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
Are you saying that people will expect Module methods to be detachable like 
this?

Original comment by [email protected] on 27 Jul 2007 at 10:26

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
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 [email protected] on 27 Jul 2007 at 10:38

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
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 [email protected] on 27 Jul 2007 at 10:57

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
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 [email protected] on 27 Jul 2007 at 11:10

from base2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 17, 2024
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 [email protected] on 10 Aug 2007 at 4:21

  • Changed state: Fixed

from base2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.