我是Slack的新手,刚创建了我的第一个频道.在设置频道时,我添加了一个目的,但是一旦创建,还有一个添加主题的地方.频道的目的与主题有什么区别?它们看起来像是一样的东西.
我是Javascript的新手,我想知道是否故意从函数中返回undefined值是一种常见的做法.
例如,应该像这样实现divide()函数:
var divide1 = function (x, y) {
if (y === 0) {
return undefined;
}
return x/y;
};
Run Code Online (Sandbox Code Playgroud)
或者像这样?
var divide2 = function (x, y) {
if (y === 0) {
throw new Error("Can't divide by 0");
}
return x/y;
};
Run Code Online (Sandbox Code Playgroud)
我假设返回undefined通常保留给没有返回值的函数(相当于Java或C#中的void).
我认识的开发人员倾向于反复调用相同的JQuery选择器,而不是将结果存储在变量中.它们与这种方法一致.
例如,他们这样做:
var propName = $(this).attr('data-inv-name');
var propValue = $(this).attr('data-inv-value');
Run Code Online (Sandbox Code Playgroud)
而不是这个:
var current = $(this);
var propName = current.attr('data-inv-name');
var propValue = current.attr('data-inv-value');
Run Code Online (Sandbox Code Playgroud)
后一种方法对我来说是正确的,但也许我错过了一些东西.这是一个简单的例子,但我看到$(this)在同一个函数中重复了几十次.
使用JQuery进行开发的最佳实践是什么?重复调用选择器还是存储在变量中?