Suggested Stdlib.listProps chagne

Discussion of the xtools Toolkit

Moderators: xbytor, DavideBarranca, Paul MR

Mike Hale

Suggested Stdlib.listProps chagne

Postby Mike Hale » Mon Jan 30, 2012 7:55 pm

I have been using listProps and found that I would like results listed in alphabetical order. Below is the modified function I came up with.
Code: Select allStdlib.listProps = function(obj) {
  var s = [];
  var sep = (isBridge() ? "\r" : "\r\n");
  for (var x in obj) {
    var str = x + ":\t";
    try {
      var o = obj[x];
      str += (typeof o == "function") ? "[function]" : o;
    } catch (e) {
    }
    s.push( str + sep );
  }
  s.sort();
  str="";
  for(var p=0;p<s.length;p++){
     str += s[p];
  }
  return str.replace(/.$/,'');
};

xbytor

Suggested Stdlib.listProps chagne

Postby xbytor » Tue Jan 31, 2012 12:00 am

Will this do?

Code: Select allStdlib.listProps = function(obj) {
  var s = [];
  var sep = (isBridge() ? "\r" : "\r\n");

  for (var x in obj) {
    var str = x + ":\t";
    try {
      var o = obj[x];
      str += (typeof o == "function") ? "[function]" : o;
    } catch (e) {
    }
    s.push(str);
  }
  s.sort();

  return s.join(sep);
};

Mike Hale

Suggested Stdlib.listProps chagne

Postby Mike Hale » Tue Jan 31, 2012 1:12 am

Knew you would be able to come up with a better way. Thanks.


Return to “xtools”

Who is online

Users browsing this forum: No registered users and 1 guest