TL,DR: 务必总是在构建函数里定义实例属性。
function WorldA () {
// ...
}
WorldA.prototype = {
xhr = new XMLHttpRequest() | |
# 进度 | |
xhr.upload.addEventListener "progress", uploadProgress, false | |
# 完成 | |
xhr.addEventListener "load", uploadComplete, false | |
xhr.addEventListener "error", console.log, false | |
xhr.addEventListener "abort", console.log, false |
/* original link http://blog.gasolin.idv.tw/2014/11/flux-javascript.html */ | |
// Renderer.js | |
var ClickRenderer = { | |
init: function s_init(element, Store) { | |
this.element = element; | |
this.store = Store; | |
window.addEventListener('render_view1', this); | |
}, | |
handleEvent: s_handleEvent(evt) { |
/* | |
* The module amap below is a simplest implementation, there is no any updated or proper libraries when I wrote it. | |
* Since there is a new full-feature library which wrote by another guy, so I just recommend it below. | |
* https://github.com/leftstick/angular-amap | |
* | |
* If you just want version with a few features like below, you could just build your version on top of it. | |
*/ | |
angular.module('amap', []) | |
.constant('amapConstant', { |
var vm = require('vm'), | |
code = 'var square = n * n;', | |
fn = new Function('n', code), | |
script = vm.createScript(code), | |
sandbox; | |
n = 5; | |
sandbox = { n: n }; | |
benchmark = function(title, funk) { |
Highcharts.Chart.prototype.callbacks.push(function(chart) { | |
var hasTouch = hasTouch = document.documentElement.ontouchstart !== undefined, | |
mouseTracker = chart.tracker, | |
container = chart.container, | |
mouseMove; | |
mouseMove = function (e) { | |
// let the system handle multitouch operations like two finger scroll | |
// and pinching | |
if (e && e.touches && e.touches.length > 1) { |
/* | |
* Usage: | |
* | |
* As a decorator: | |
* | |
* import defaultTheme from './style.scss'; | |
* | |
* @themr(defaultTheme) | |
* class Comp extends React.Component { ... } | |
* |
/** | |
* @decorator | |
* Attach events to DOM element | |
* | |
* @param {Element|Function} elemOrFunc: DOM Element, or a function returns element | |
* @param {String} events: a list events separated with ',' | |
* | |
* Usage: | |
* @attachEvents(window, 'click') | |
* handleWindowClick(evt) { |
/** | |
* Angular $rootScope.Scope.$once | |
* Copyright (c) 2014 marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
*/ | |
$provide.decorator('$rootScope', function ($delegate) { | |
var Scope = $delegate.__proto__.constructor; | |
Scope.prototype.$once = function (name, listener) { | |
var deregister = this.$on(name, function () { | |
deregister(); |
body { | |
margin: 0; | |
padding: 0; | |
background-color: #fff; | |
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAANUlEQVQ4jWM8c+bMfwY8wNjYmBGfPBM+SWLAqAGDwQDG///xJgOGs2fP4lUw8F4YNYAKBgAA2NYKfxDn4ZUAAAAASUVORK5CYII=); | |
overflow: hidden; | |
} |