Suggested Stdlib.listProps chagne

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

Mike Hale

Suggested Stdlib.listProps chagne

Post 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(/.$/,'');
};
xbytor

Suggested Stdlib.listProps chagne

Post 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);
};
Mike Hale

Suggested Stdlib.listProps chagne

Post by Mike Hale »

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