Bleeding Scope Variables
How do I make an bleeding scope variables?
This pen showcase a typical JS scope variable bleeding from within an Angular controller due to the fact that it was not declared properly.. What is a bleeding scope variables? How do you make a bleeding scope variables? This script and codes were developed by Ian Joubert on 10 November 2022, Thursday.
Bleeding Scope Variables - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Bleeding Scope Variables</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.11.4/angular-material.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="app" ng-app="app" ng-controller="Ctrl1 as Ctrl1" layout="column" layout-fill>
</div>
<div ng-controller="Ctrl2 as Ctrl2" layout="column" layout-fill>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.0.5/bluebird.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.11.4/angular-material.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular-animate.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular-aria.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular-messages.js'></script>
<script src='https://cdn.rawgit.com/Studira/mediawiki-js/master/MediawikiJS.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-resource.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Bleeding Scope Variables - Script Codes CSS Codes
body { font-family: roboto;
}
#console,
#output { background: rgba(0, 0, 0, 0.05)
}
h3 { margin: 0;
}
p{ margin:4px 0;
}
Bleeding Scope Variables - Script Codes JS Codes
// -------------------------------------------------------------------------------- // CODEPENIO - UI for logging and outputting results // -------------------------------------------------------------------------------- var sec = -0.4, factor = 0.4; //Output results to output div function log(arg) { sec = (sec < -factor ? -factor : sec) + factor setTimeout(function(param) { param = '#' + moment().format('hh:mm:ss') + ' ' + (_.isPlainObject(param) ? JSON.stringify(param) : param); console.log(param); $('#console span').html(param); }.bind(null, arg), sec * 1000); } //Logging to console div function output(arg) { sec = (sec < -factor ? -factor : sec) + factor setTimeout(function(param) { //console.log(param); param = _.isObject(param) ? JSON.stringify(param) : String(param); $('#output p').html(param); }.bind(null, arg), sec * 1000); } //Logging all window errors to console div window.onerror = function(msg, url, lineNo) { lineNo = ('000000000' + lineNo).substr(-4) log('(line ' + lineNo + ') ' + 'Error: ' + msg) $('#console').css('color', 'red'); } // -------------------------------------------------------------------------------- // HELPERS - Helper functions // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // ANGULARJS - Angular application // -------------------------------------------------------------------------------- var app = angular.module('app',[])
//This controller's privacy is not protected by an IIFE and hence its var is bleeding into the global namespace. app.controller('Ctrl1', [function(){ var private1 = {data:'This is private data'}; public1 = {data:'This is not private data'}; }]) console.log(app);
//This controller's privacy is protected by an IIFE. It prevents vars bledding into global namespace
(function(){ app.controller('Ctrl2', [function(){ var private2 = {data:'This is private data'}; public2 = {data:'This is not private data'}; }])
})()
window.setTimeout(function(){ console.log('private1: ',_.has(window,'private1')); console.log('public1: ',_.has(window,'public1')); console.log('private2: ',_.has(window,'private2')); console.log('public2: ',_.has(window,'public2')); console.log(window)
},2000)
Developer | Ian Joubert |
Username | Studira |
Uploaded | November 10, 2022 |
Rating | 3 |
Size | 2,734 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Angular Directive - Tracking element width | 3,316 Kb |
Multi column sort with sorting direction per column | 4,196 Kb |
Probabilistic N-Gram Dataset Merge | 19,294 Kb |
Asynchronous Functions | 3,150 Kb |
Hashing Credit Card Number | 2,771 Kb |
Processing Asynchronous Data | 3,264 Kb |
Changing CMYK colors into RGB and Hex values | 3,173 Kb |
Facebook Profile Pictures - Flag Over | 6,841 Kb |
Angular Test Template | 2,545 Kb |
Parsing Locale data from official source | 5,255 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Canvas stripes | Adrianparr | 1,948 Kb |
Brown by pure CSS, no image, no javascript | Aaronchuo | 2,652 Kb |
Wikipedia Viewer | Thalpha | 4,426 Kb |
React Markdown Previewer | C0d0er | 3,190 Kb |
Speech bubbles | Something | 1,547 Kb |
Learning canvas drawing | Aurer | 2,204 Kb |
STAR WARS LIGHTSABER | Francoiscoron | 4,420 Kb |
Fluid Grid 12 | Alexoliverwd | 2,309 Kb |
A Pen by Anoop | Anoopjohn | 330,760 Kb |
Login-ng-modal | Heedoo | 3,566 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!