spacevillain (spacevillain) wrote in changelog,
spacevillain
spacevillain
changelog

[livejournal] r23274: LJSUP-14206: es5-shim

Committer: atyurin
LJSUP-14206: es5-shim
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-11-09 07:52:14 UTC (rev 23273)
+++ trunk/htdocs/js/basic.js	2012-11-09 08:35:08 UTC (rev 23274)
@@ -1164,6 +1164,41 @@
 	}
 });
 
+// for back compatiblity with legacy code 
+if (jQuery.browser.msie && Number(jQuery.browser.version) < 9) {
+	Function.prototype.bind = function(that) { // .length is 1
+		var target = this,
+			slice = [].slice;
+		if (typeof target.apply != "function" || typeof target.call != "function")
+			return new TypeError();
+
+		var args = slice.call(arguments, 1); // for normal call
+		var bound = function () {
+
+			if (this instanceof bound) {
+
+				var self = Object.create(target.prototype);
+				var result = target.apply(
+					self,
+					args.concat(slice.call(arguments))
+				);
+				if (result !== null && Object(result) === result)
+					return result;
+				return self;
+
+			} else {
+				return target.apply(
+					that,
+					args.concat(slice.call(arguments))
+				);
+
+			}
+		};
+
+		return bound;
+	}
+}
+
 Object.extend(Function, {
 	defer: function(func, args/*, more than one*/) {
 		args = Array.prototype.slice.call(arguments, 1);

Tags: atyurin, js, livejournal, spacevillain
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments