Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

console.dir の Add-on SDK実装

View console-dir.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
// @file console-dir.js
// @brief
// @author ongaeshi
// @date 2011/06/02
//
// --------------------------------------
// console.dir({a: 1, b: 2, c: 3});
// =>
// info:
// a: 1
// b: 2
// c: 3
//
//
// --------------------------------------
// console.dir_s({a: 1, b: 2, c: 3});
// => "info:\n a: 1\n b: 2\n c: 3"
//
// --------------------------------------
// console.dir({f1: function() {}, f2: function() {}, f3: function() {}}, "Disp functions.");
// =>
// info:
// Disp functions.
// f1()
// f2()
// f3()
//
// --------------------------------------
// console.dir({f1: function() {}, a : 1, b : 2, funcs: function() {}}, "property & function");
// =>
// info:
// property & function
// property:
// a: 1
// b: 2
// function:
// f1()
// funcs()
//
// --------------------------------------
// const panel = require('panel');
// console.dir(panel.Panel({
// width: 800,
// height: 800,
// contentURL: data.url('index.html'),
// contentScriptFile: [data.url('game.js')],
// contentScriptWhen: 'ready'
// }));
// =>
// info:
// property:
// allow: [object Object]
// contentScript: null
// contentScriptFile: resource://jid1-ckmgqls2uqipog-enchant-test-data/game.js
// contentScriptWhen: "ready"
// contentURL: "resource://jid1-ckmgqls2uqipog-enchant-test-data/index.html"
// height: 800
// isShowing: false
// port: [object Trait]
// width: 800
// function:
// destroy()
// hide()
// on()
// once()
// postMessage()
// removeListener()
// resize()
// show()
//
// --------------------------------------
 
console.dir_s = function (object, msg) {
var disp_properties = function (properties, indent, out) {
for (var i = 0; i < properties.length; ++i) {
var name = properties[i][0], value = properties[i][1];
 
if (typeof value == "string")
value = '"' + value + '"';
 
out.push(indent + name + ": " + value);
}
};
var disp_funcs = function (funcs, indent, out) {
for (var i = 0; i < funcs.length; ++i) {
var name = funcs[i][0], value = funcs[i][1];
out.push(indent + name + "()");
}
};
 
var pairs = [];
for (var name in object) {
try {
pairs.push([name, object[name]]);
}
catch (exc) {
}
}
pairs.sort(function(a, b) { return a[0] < b[0] ? -1 : 1; });
 
var properties = [];
var funcs = [];
for (var i = 0; i < pairs.length; ++i) {
switch (typeof pairs[i][1]) {
case "function":
funcs.push(pairs[i]);
break;
default:
properties.push(pairs[i]);
break;
}
}
 
var out = [];
 
out.push("");
if (msg != null)
out.push(msg);
 
if (properties.length > 0 && funcs.length != 0) {
out.push(" property:");
disp_properties(properties, " ", out);
} else {
disp_properties(properties, " ", out);
}
 
if (funcs.length > 0 && properties.length != 0) {
out.push(" function:");
disp_funcs(funcs, " ", out);
} else {
disp_funcs(funcs, " ", out);
}
return out.join("\n");
}
 
console.dir = function (object, msg) {
console.log(console.dir_s(object, msg));
}
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.