1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is Google Safe Browsing.
16 # The Initial Developer of the Original Code is Google Inc.
17 # Portions created by the Initial Developer are Copyright (C) 2006
18 # the Initial Developer. All Rights Reserved.
21 # Aaron Boodman <aa@google.com> (original author)
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the GPL or the LGPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
35 # ***** END LICENSE BLOCK *****
39 * lang.js - Some missing JavaScript language features
43 * Partially applies a function to a particular "this object" and zero or
44 * more arguments. The result is a new function with some arguments of the first
45 * function pre-filled and the value of |this| "pre-specified".
47 * Remaining arguments specified at call-time are appended to the pre-
51 * var barMethBound = BindToObject(myFunction, myObj, "arg1", "arg2");
52 * barMethBound("arg3", "arg4");
54 * @param fn {string} Reference to the function to be bound
56 * @param self {object} Specifies the object which |this| should point to
57 * when the function is run. If the value is null or undefined, it will default
58 * to the global object.
60 * @returns {function} A partially-applied form of the speficied function.
62 function BindToObject(fn, self, opt_args) {
63 var boundargs = fn.boundArgs_ || [];
64 boundargs = boundargs.concat(Array.slice(arguments, 2, arguments.length));
71 var newfn = function() {
72 // Combine the static args and the new args into one big array
73 var args = boundargs.concat(Array.slice(arguments));
74 return fn.apply(self, args);
77 newfn.boundArgs_ = boundargs;
78 newfn.boundSelf_ = self;
85 * Inherit the prototype methods from one constructor into another.
89 * function ParentClass(a, b) { }
90 * ParentClass.prototype.foo = function(a) { }
92 * function ChildClass(a, b, c) {
93 * ParentClass.call(this, a, b);
96 * ChildClass.inherits(ParentClass);
98 * var child = new ChildClass("a", "b", "see");
99 * child.foo(); // works
101 * In addition, a superclass' implementation of a method can be invoked
104 * ChildClass.prototype.foo = function(a) {
105 * ChildClass.superClass_.foo.call(this, a);
109 Function.prototype.inherits = function(parentCtor) {
110 var tempCtor = function(){};
111 tempCtor.prototype = parentCtor.prototype;
112 this.superClass_ = parentCtor.prototype;
113 this.prototype = new tempCtor();