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 () { | |
| // Change root to point at your ng-app in HTML | |
| var root = $(document.getElementsByTagName('body')); | |
| var watchers = []; | |
| var f = function (element) { | |
| if (element.data().hasOwnProperty('$scope')) { | |
| angular.forEach(element.data().$scope.$$watchers, | |
| function (watcher) { | |
| watchers.push(watcher); |
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
| <!-- must always supply an href to file --> | |
| <a href="/file/somethingreallylongandobscure234211.pdf" download> | |
| <!-- if a value is passed to download attr, it will be the name of the file when downloaded --> | |
| <a href="/file/generated-budget-1293.pdf" download="Weekly Budget Recap"> |
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
| //globals | |
| var x = 4; | |
| function Dog() { | |
| alert("Woof"); | |
| } | |
| // 3rd party libraries use the global scope | |
| // making them accessible from anywhere an app | |
| jQuery("#myDiv").empty(); |
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
| // Attempt #1: using typeof | |
| // fails in all cases since typeof [] returns "object" | |
| Array.prototype.isArray = function(obj) { | |
| return (typeof obj === "array"); | |
| } | |
| // Attempt #2: using instanceof | |
| // fails when obj = Array.prototype | |
| // and when array is defined in another window or frame | |
| Array.prototype.isArray = function(obj) { |
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 Animal(hasFeathers, sound) { | |
| this.hasFeathers = hasFeathers; | |
| this.sound = sound; | |
| } | |
| Animal.prototype.isDuck = function() { | |
| if (this.hasFeathers && this.sound === "Quack") { | |
| console.log("I am a duck"); | |
| } else { | |
| console.log("I am not a duck"); | |
| } |
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
| define([ | |
| 'text!./Templates/mainTemplate.html', | |
| 'text!./Templates/messageTemplate.html' | |
| ], function ( | |
| maintemplate, | |
| messageTemplate | |
| ) { | |
| 'use strict'; | |
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
| // The following results in a syntax error. | |
| var a = 'a' | |
| [].forEach.call(document.querySelectorAll('.md'), function(e) { | |
| console.log(e); | |
| }); | |
| // Adding the semicolon and now everything works just fine. | |
| var a = 'a'; | |
| [].forEach.call(document.querySelectorAll('.md'), function(e) { | |
| console.log(e); |
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
| ====================================================== | |
| // The magnitude of this hack compares favorably with that of the US national debt. | |
| ====================================================== | |
| // Warning: Thar be dragons lurkin and black magic at work here. | |
| // Modify at your own risk! | |
| // | |
| // ^ ^ |
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 Dog (name, breed) { | |
| // instance variables | |
| this.name = name; | |
| this.breed = breed; | |
| var medicalRecords = { | |
| "hasWorms": true, | |
| "hasDiabetes": 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
| // create a closure and remap jQuery to $ | |
| (function($){ | |
| // save off original method | |
| var _originalAppendTo = $.fn.appendTo; | |
| // override method | |
| $.fn.appendTo = function() { | |
| // silly code to alternate backgound color | |
| if ($(document.body).children().length % 2) { | |
| document.body.style.background = "#f285cf"; |
OlderNewer