Ticket #250 (new defect)

Opened 1 year ago

Last modified 1 year ago

MochiKit.Base.repr does not have the intended behaviour for functions

Reported by: xverges@gmail.com Assigned to: somebody
Priority: normal Milestone: MochiKit 1.5
Component: component1 Version:
Severity: minor Keywords:
Cc:

Description

The code section that deals with functions that do not have a NAME attribute is buidling a string representation that later is not returned.

I edited the code to take care of this, and also thought that it would be nice to return a part of the function body for anonymous functions

MochiKit.Base.repr(o)
{
...
if (typeof(o) == "function") {
  ostring = ostring.replace(/\s+/g, " ");
  ostring = ostring.replace(/^\s+/, "");
  if (ostring.match(/^function\s*\(/)) {
    var limit = 60;
    ostring = ostring.substr(0, limit) + (ostring.length>limit? "...":"");
  } else {
    var idx = ostring.indexOf("{");
    if (idx != -1) {
      ostring = ostring.substr(0, idx) + "{...}";
    }
  }
}

Change History

05/10/07 04:53:39 changed by therve@gmail.com

I applied a partial fix in [1288]. I didn't find it accurate to print functions body, but at least it does now make the intended modifications.

05/10/07 15:44:10 changed by xverges@gmail.com

Nice! I have to agree with the very limited usefullness of partial function bodies.

On a related note, I was wondering if it could be usefull to do something to allow the use of the MochiKit.Base.bind family but still keep some meaningfull repr by adding a NAME attribute to the new function if the argument function had one.

E.g. at the end of bind()

if (typeof(im_func.NAME) == 'string') {
  newfunc.NAME = "bind(" + im_func.NAME + ",...)";
}

05/14/07 17:49:58 changed by rsayre@mozilla.com

  • severity changed from normal to minor.
  • milestone set to MochiKit 1.5.

Would be nice, but shouldn't block a release, right? Moving to 1.5.