虽然.map()方法的接口是.map( callback(index, domElement) ),但它是$.map( array, callback(elementOfArray, indexInArray) )$ .map()...有什么想法为什么$ .map()选择将返回的参数放在诸如value-index的顺序中?
在设置jQuery的路径时,每当我使用时:
require.config({
paths: {
'jQuery': './libs/jquery-1.8.0.min'
}
});
Run Code Online (Sandbox Code Playgroud)
然后:
define(['jQuery'], function($) {
console.log($);
};
Run Code Online (Sandbox Code Playgroud)
$ 将是不确定的.
但是,如果我使用:
require.config({
paths: {
'jquery': './libs/jquery-1.8.0.min'
}
});
Run Code Online (Sandbox Code Playgroud)
然后:
define(['jquery'], function($) {
console.log($);
};
Run Code Online (Sandbox Code Playgroud)
所有事情都突然变得很好.
定义jQuery的别名有jQuery什么问题?
我对两者之间的差异感到困惑.似乎Collection.create()(fires add和syncevents)可以看作是Collection.add()(fires add)和Model.save()(fires sync)的组合?
以上评估是否正确?我错过了什么?
我遇到了一种相当奇特的行为 - 我的RequireJS模块似乎没有在IE9下初始化和运行:
<head>
...
<script data-main="/static/js/main" src="/static/js/libs/require.js"></script> // Seems to be not running at all.
</head>
Run Code Online (Sandbox Code Playgroud)
但是,每当我启动IE9的开发人员工具并重新加载页面时,模块就会像在Firefox/Chrome/Safari /等中一样正常运行.清理浏览器缓存并关闭IE9中的开发人员工具将导致JavaScript无法再次完全运行.
另一种启动RequireJS模块执行的方法是在它之前添加一个同步脚本:
<head>
...
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> // Add any synchronous script calling here and the module below will execute fine.
<script data-main="/static/js/main" src="/static/js/libs/require.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
似乎奇怪行为的原因可能是:
但是,为什么开发人员工具可以启动执行实际上让我感到困惑.
寻找对该现象的完整解释以及如何解决它.
javascript internet-explorer asynchronous internet-explorer-9 requirejs
jQuery如何实现其Deferred对象,以便new运算符是可选的var x = $.Deferred();?
我目前正在使用Backbone.Mediator在我的Backbone + RequireJS项目中利用Mediator Pattern的好处; 然而,我遇到了一个模式的特殊行为,不太确定它是"按设计",或者更确切地说,不是Mediator Pattern的标准行为,而是插件中的错误.
作为一个人为的例子:
AMD模块1
var View1 = Backbone.View.extend({
...
events: {
'click div: switchList'
},
switchList: function() {
Backbone.Mediator.pub('list:switch');
}
});
Run Code Online (Sandbox Code Playgroud)
AMD模块2
var View2 = Backbone.View.extend({
...
subscriptions: {
'list:switch': 'shrinkDiv'
},
shrinkDiv: function() {
Backbone.Mediator.pub('div:shrink');
this.shrinkAndMore();
}
});
return View2;
Run Code Online (Sandbox Code Playgroud)
AMD模块3
define(function(require) {
var View2 = require(**AMD Module 2**);
var View3 = Backbone.View.extend({
...
subscriptions: {
'div:shrink': 'createSiblingDiv'
},
createSiblingDiv: function() {
this.siblingView = new View2();
this.$el.after(this.siblingView.$el);
this.siblingView.render();
}
});
});
Run Code Online (Sandbox Code Playgroud)
我以为它会像这样工作:
**View1**.switchList(); …Run Code Online (Sandbox Code Playgroud) 之间有什么区别:
function Gandalf() {
this.color = 'grey';
}
Gandalf.prototype.comeBack = function() {
this.color = 'white';
}
Run Code Online (Sandbox Code Playgroud)
和:
function Gandalf() {
this.color = 'grey';
this.comeBack = function() {
this.color = 'white';
return this;
};
}
Run Code Online (Sandbox Code Playgroud)
在什么情况下我应该将该方法挂接到原型上,或者不挂接?
在angular.element只有一个next()方法,但prev().有没有办法模拟prev()Angular/jqLite 的行为?
说我得到以下HTML结构:
<body ng-app="demo" ng-controller="RootCtrl">
<header>
<!-- Header Material -->
</header>
<main ng-controller="MainCtrl">
<!-- Main Content -->
<nav ng-controller="NavCtrl">
<!-- Navbar -->
</nav>
</main>
<body>
Run Code Online (Sandbox Code Playgroud)
现在,假设NavCtrl需要操纵恰好存在于RootCtrl范围内的模型 - 在哪种条件下$emit/$on更适合?在哪些条件下通过范围继承直接操作模型会更好?
javascript architecture inheritance prototypal-inheritance angularjs
var app = express.createServer();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);`
Run Code Online (Sandbox Code Playgroud)
我找不到有关res.sendNode.js手册内部的相应参考资料:
http://nodejs.org/docs/v0.4.12/api/http.html#http.ServerResponse
它是一个未记录的属性,还是将该属性作为HTTP的固有部分?如果是这样,我在哪里可以找到所有属性的相应参考?
javascript ×5
jquery ×4
requirejs ×3
angularjs ×2
backbone.js ×2
architecture ×1
asynchronous ×1
express ×1
http ×1
inheritance ×1
mediator ×1
new-operator ×1
node.js ×1
prototype ×1