当Angular应用发布时,开发者需要考虑以下问题:
This file contains 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
const EventEmitter = require('events'); | |
const event = new EventEmitter(); | |
// 添加一个事件监听器 | |
event.on('bar', function() { | |
console.log('bar fired!'); | |
}) | |
// 触发一个事件 |
This file contains 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 isPromise(object){ | |
if(Promise && Promise.resolve){ | |
return Promise.resolve(object) == object; | |
}else{ | |
throw "Promise not supported in your environment" | |
} | |
} | |
var i = 1; | |
var p = new Promise(function(resolve,reject){ |
This file contains 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
import fs from 'fs'; | |
import path from 'path'; | |
const convert = (imgPath) => { | |
// read image file | |
fs.readFile(imgPath, (err, data)=>{ | |
// error handle | |
if(err) { | |
throw err; | |
} |
This file contains 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 root = angular.element(document.querySelectorAll("body")); | |
var totalWatchers = []; | |
//通过data()方法找到DOM对应的$scope, 轮询所有子$scope的$$watchers数量 | |
var calcWatcher = function (element) { | |
angular.forEach(['$scope', '$isolateScope'], function (scope) { | |
if (element.data() && element.data().hasOwnProperty(scope)) { | |
angular.forEach(element.data()[scope].$$watchers, function (watcher) { |