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
| <!DOCTYPE HTML> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Performance: NodeList vs. Array</title> | |
| <script type="text/javascript"> | |
| var result = document.evaluate( | |
| // 1. <div> id == main | |
| // 2. 3rd <p> class == content | |
| // 3. <a> starts with href http://example.com/ |
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
| <!DOCTYPE HTML> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Performance race</title> | |
| </head> | |
| <body> | |
| <h1>Performance race: NodeList vs. Array</h1> | |
| <p>Check the console.</p> | |
| <div> |
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
| //Array.prototype.slice() | |
| var nodeList = decument.getElementsByTagname('span'); | |
| alert(nodeList instanceof NodeList); // => true | |
| alert(nodeList instanceof Array); // => false | |
| var array = Array.prototype.slice.call(nodeList); | |
| alert(array instanceof NodeList); // => false | |
| alert(array instanceof Array); // => true |
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 elem = document.createElement('div'), | |
| text = document.createTextNode('Added div element.'); | |
| document.body.appendChild(elem); | |
| elem.appendChild(text); | |
| var comment - document.createComment('This is comment.'); | |
| document.body.insertBefore(comment, elem); |
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 fragment = document.createDocumentFragment(); | |
| for (var i = 0; i < 10; i++) { | |
| var child = document.createElement('div'); | |
| // here | |
| fragment.appendChild(child); | |
| } | |
| document.getElementById('parent').appendChild(fragment); |
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
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use GD; | |
| sub draw_page { | |
| my ($width, $height) = @_; | |
| return unless $width && $height; |
NewerOlder