Template:jsOverrides

  • Revision slug: Template:jsOverrides
  • Revision title: Template:jsOverrides
  • Revision id: 321797
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

<% /** * Replaces Template:JSInherits. Given an object and a list of properties or * methods implemented elsewhere, output a list of the properties or methods * inherited from that object. * * TODO: make it work with an inheritance chain, e.g., if you want inherited * properties or methods from both Function and Object, where Function itself * overrides methods from Object. We don't want to see that it inherits a * "valueOf" method from Function and again on Object. * * @param the object to inherit from * @param "properties" or "methods" * @param a list of properties or methods overridden by this object */ var prototypes = { "Array": { methods: [ "pop", "push", "reverse", "shift", "sort", "splice", "unshift", "concat", "join", "slice", "toSource", "toString", "indexOf", "lastIndexOf", "filter", "forEach", "every", "map", "some", "reduce", "reduceRight" ], properties: [ "constructor", "index", "input", "length" ] }, "Boolean": { methods: [ "toSource", "toString", "valueOf" ], properties: [ "constructor" ] }, "Date": { methods: [ "getDate", "getDay", "getFullYear", "getHours", "getMilliseconds", "getMinutes", "getMonth", "getSeconds", "getTime", "getTimezoneOffset", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth", "getUTCSeconds", "getYear", "setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth", "setSeconds", "setTime", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "setYear", "toDateString", "toGMTString", "toLocaleDateString", "toLocaleFormat", "toLocaleString", "toLocaleTimeString", "toSource", "toString", "toTimeString", "toUTCString", "valueOf" ], properties: [ "constructor" ] }, "Error": { methods: [ "toSource", "toString" ], properties: [ "constructor", "message", "name", "description", "number", "fileName", "lineNumber", "stack" ] }, "EvalError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] }, "Function": { methods: [ "apply", "call", "toSource", "toString" ], properties: [ "arity", "caller", "constructor", "length", "name" ] }, "Number": { methods: [ "toExponential", "toFixed", "toLocaleString", "toPrecision", "toSource", "toString", "valueOf" ], properties: [ "constructor" ] }, "Object": { methods: [ "__defineGetter__", "__defineSetter__", "hasOwnProperty", "isPrototypeOf", "__lookupGetter__", "__lookupSetter__", "__noSuchMethod__", "propertyIsEnumerable", "toSource", "toLocaleString", "toString", "unwatch", "valueOf", "watch" ], properties: [ "constructor", "__parent__", "__proto__" ] }, "RangeError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] }, "ReferenceError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] }, "RegExp": { methods: [ "exec", "test", "toSource", "toString" ], properties: [ "constructor", "global", "ignoreCase", "lastIndex", "multiline", "source" ] }, "String": { methods: [ "charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "localeCompare", "match", "quote", "replace", "search", "slice", "split", "substr", "substring", "toLocaleLowerCase", "toLocaleUpperCase", "toLowerCase", "toSource", "toString", "toUpperCase", "trim", "trimLeft", "trimRight", "valueOf", "anchor", "big", "blink", "bold", "fixed", "fontcolor", "fontsize", "italics", "link", "small", "strike", "sub", "sup" ], properties: [ "constructor", "length" ] }, "SyntaxError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] }, "TypeError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] }, "URIError": { methods: [ "toSource", "toString" ], properties: [ "constructor", "name" ] } }; var prefix; if ('en-US' == env.locale) { prefix = '/en-US/docs/JavaScript/Reference/Global_Objects/'; } var captiontext = string.ToUpperFirst(string.toLower($1)) + ' inherited from '; var pageuri = wiki.uri(prefix + $0); var htmlstring = '' + captiontext + ' ' + $0 + ':
'; %> <%- htmlstring %> <% var desiredprototype = prototypes[$0][string.toLower($1)]; var overrides = arguments.slice(2); for (var i=0; i<overrides.length; !="(-1))" $0="" '="" ''));="" '__',="" (index="" (var="" +="" -="" 1);="" 1;="" ;="" desiredprototype="desiredprototype.splice(index," for="" href="' + pageuri + '" htmlstring="&lt;span style="font-size: smaller;"&gt;" i="0;" i++)="" i<desiredprototype.length;="" if="" index="desiredprototype.indexOf(override);" lastindex="desiredprototype.length" override="overrides[i];" p="desiredprototype[i];" pageuri="wiki.uri(prefix" parts="[];" parts.push('<a="" pimproper="string.ToUpperFirst(string.replace(p," pimproper);="" var="" {="" }="">' + p + ''); } htmlstring += parts.join(', ') + ''; %> <%- htmlstring %> </overrides.length;>

Revision Source

<div style="border: 1px solid rgb(204, 204, 204); margin: 10px 0px; padding: 0px 10px; background: rgb(238, 238, 238) none repeat scroll 0% 0%;">
<%
/**
 * Replaces Template:JSInherits. Given an object and a list of properties or
 * methods implemented elsewhere, output a list of the properties or methods
 * inherited from that object.
 *
 * TODO: make it work with an inheritance chain, e.g., if you want inherited
 * properties or methods from both Function and Object, where Function itself
 * overrides methods from Object. We don't want to see that it inherits a
 * "valueOf" method from Function and again on Object.
 *
 * @param the object to inherit from
 * @param "properties" or "methods"
 * @param a list of properties or methods overridden by this object
 */
var prototypes = {
  "Array": {
    methods: [
      "pop",
      "push",
      "reverse",
      "shift",
      "sort",
      "splice",
      "unshift",
      "concat",
      "join",
      "slice",
      "toSource",
      "toString",
      "indexOf",
      "lastIndexOf",
      "filter",
      "forEach",
      "every",
      "map",
      "some",
      "reduce",
      "reduceRight"
    ],
    properties: [
      "constructor",
      "index",
      "input",
      "length"
    ]
  },
  "Boolean": {
    methods: [
      "toSource",
      "toString",
      "valueOf"
    ],
    properties: [
      "constructor"
    ]
  },
  "Date": {
    methods: [
      "getDate",
      "getDay",
      "getFullYear",
      "getHours",
      "getMilliseconds",
      "getMinutes",
      "getMonth",
      "getSeconds",
      "getTime",
      "getTimezoneOffset",
      "getUTCDate",
      "getUTCDay",
      "getUTCFullYear",
      "getUTCHours",
      "getUTCMilliseconds",
      "getUTCMinutes",
      "getUTCMonth",
      "getUTCSeconds",
      "getYear",
      "setDate",
      "setFullYear",
      "setHours",
      "setMilliseconds",
      "setMinutes",
      "setMonth",
      "setSeconds",
      "setTime",
      "setUTCDate",
      "setUTCFullYear",
      "setUTCHours",
      "setUTCMilliseconds",
      "setUTCMinutes",
      "setUTCMonth",
      "setUTCSeconds",
      "setYear",
      "toDateString",
      "toGMTString",
      "toLocaleDateString",
      "toLocaleFormat",
      "toLocaleString",
      "toLocaleTimeString",
      "toSource",
      "toString",
      "toTimeString",
      "toUTCString",
      "valueOf"
    ],
    properties: [
      "constructor"
    ]
  },
  "Error": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "message",
      "name",
      "description",
      "number",
      "fileName",
      "lineNumber",
      "stack"
    ]
  },
  "EvalError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  },
  "Function": {
    methods: [
      "apply",
      "call",
      "toSource",
      "toString"
    ],
    properties: [
      "arity",
      "caller",
      "constructor",
      "length",
      "name"
    ]
  },
  "Number": {
    methods: [
      "toExponential",
      "toFixed",
      "toLocaleString",
      "toPrecision",
      "toSource",
      "toString",
      "valueOf"
    ],
    properties: [
      "constructor"
    ]
  },
  "Object": {
    methods: [
      "__defineGetter__",
      "__defineSetter__",
      "hasOwnProperty",
      "isPrototypeOf",
      "__lookupGetter__",
      "__lookupSetter__",
      "__noSuchMethod__",
      "propertyIsEnumerable",
      "toSource",
      "toLocaleString",
      "toString",
      "unwatch",
      "valueOf",
      "watch"
    ],
    properties: [
      "constructor",
      "__parent__",
      "__proto__"
    ]
  },
  "RangeError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  },
  "ReferenceError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  },
  "RegExp": {
    methods: [
      "exec",
      "test",
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "global",
      "ignoreCase",
      "lastIndex",
      "multiline",
      "source"
    ]
  },
  "String": {
    methods: [
      "charAt",
      "charCodeAt",
      "concat",
      "indexOf",
      "lastIndexOf",
      "localeCompare",
      "match",
      "quote",
      "replace",
      "search",
      "slice",
      "split",
      "substr",
      "substring",
      "toLocaleLowerCase",
      "toLocaleUpperCase",
      "toLowerCase",
      "toSource",
      "toString",
      "toUpperCase",
      "trim",
      "trimLeft",
      "trimRight",
      "valueOf",
      "anchor",
      "big",
      "blink",
      "bold",
      "fixed",
      "fontcolor",
      "fontsize",
      "italics",
      "link",
      "small",
      "strike",
      "sub",
      "sup"
    ],
    properties: [
      "constructor",
      "length"
    ]
  },
  "SyntaxError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  },
  "TypeError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  },
  "URIError": {
    methods: [
      "toSource",
      "toString"
    ],
    properties: [
      "constructor",
      "name"
    ]
  }
};
var prefix;
if ('en-US' == env.locale) {
  prefix = '/en-US/docs/JavaScript/Reference/Global_Objects/';
}
var captiontext = string.ToUpperFirst(string.toLower($1)) + ' inherited from ';
var pageuri = wiki.uri(prefix + $0);
var htmlstring = '<span style="font-weight:bold;">' + captiontext +
                 ' <a href="' + pageuri + '"><code>' + $0 +
                 '</code></a></span>:<br />';
%>
<%- htmlstring %>
<%
var desiredprototype = prototypes[$0][string.toLower($1)];
var overrides = arguments.slice(2);
for (var i=0; i<overrides.length; i++) {
  var override = overrides[i];
  var index = desiredprototype.indexOf(override);
  if (index != (-1)) {
    desiredprototype = desiredprototype.splice(index, 1);
  }
}
htmlstring = '<span style="font-size: smaller;">';
var lastindex = desiredprototype.length - 1;
var i = 0;
var parts = [];
for (var i=0; i<desiredprototype.length; i++) {
  var p = desiredprototype[i];
  var pimproper = string.ToUpperFirst(string.replace(p, '__', ''));
  pageuri = wiki.uri(prefix + $0 + '/' + pimproper);
  parts.push('<a href="' + pageuri + '"><code>' + p + '</code></a>');
}
htmlstring += parts.join(', ') + '</span>';
%>
<%- htmlstring %>
</div>
Revert to this revision