Page 1 of 1

Suggested Stdlib.listProps chagne

Posted: Mon Jan 30, 2012 7:55 pm
by Mike Hale
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(/.$/,'');
};

Suggested Stdlib.listProps chagne

Posted: Tue Jan 31, 2012 12:00 am
by xbytor
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);
};

Suggested Stdlib.listProps chagne

Posted: Tue Jan 31, 2012 1:12 am
by Mike Hale
Knew you would be able to come up with a better way. Thanks.