This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Element.addMethods({ | |
| clone: function(element) { | |
| var clone = $(element).cloneNode(true); | |
| $(clone).select('*[id]').concat(clone).invoke('writeAttribute', { id: null }); | |
| return clone; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var element = document.getElementById('foo'); | |
| try { | |
| element.removeAttribute.apply(element, ['title']); | |
| // using apply to simulate what Enum#invoke does. | |
| } catch (e) { | |
| alert(e.name + ': ' + e.message); | |
| } | |
| // in IE alerts: TypeError: Object doesn't support this property or method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Point(x, y) { | |
| function getX() { | |
| return x; | |
| } | |
| function getY() { | |
| return y; | |
| } | |
| function getOriginDistance() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function concat() { | |
| var array = slice.call(this, 0), item; | |
| for (var i = 0, length = arguments.length; i < length; i++) { | |
| item = arguments[i]; | |
| if (Object.isArray(item) && !('callee' in item)) { | |
| for (var j = 0, arrayLength = item.length; j < arrayLength; j++) | |
| array.push(item[j]); | |
| } else { | |
| array.push(item); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ES_3_1_STRICT_MODE = (function(){ | |
| try { | |
| arguments.callee; | |
| } catch(e) { | |
| return true; | |
| } | |
| return false; | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Simpler, more robust super keyword for Prototype. | |
| Given the following parent class: | |
| var Person = Class.create({ | |
| initialize: function(name) { | |
| this.name = name; | |
| }, | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.extend = Object.extend.wrap(function(proceed, destination, source, safe) { | |
| if (!safe) return proceed(destination, source); | |
| for (var property in source) { | |
| if (!(property in destination)) | |
| destination[property] = source[property]; | |
| } | |
| return destination; | |
| }); | |
| Object.extend({foo: 123}, {foo: 456}, true).foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var toString = Object.prototype.toString; | |
| function isNumber(object) { | |
| return toString.call(object) === "[object Number]"; | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p(nil) | |
| #-> nil | |
| p(false) | |
| #-> false | |
| p(true) | |
| #-> true | |
| p('foo') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| repr(False) | |
| #-> False | |
| repr(True) | |
| #-> True | |
| repr(None) | |
| #-> None | |
| repr('foo') |
OlderNewer