我安装了第三方库,但找不到随附的命名空间.
The type or namespace name 'Maverick' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
足够公平,VS 2010找不到它.但是我的系统在哪里寻找第三方库?我可以修改位置列表吗?
在我正确的Javascript中进行实验,我试图从另一个方法(WaitAndSayHello)运行一个方法(SayHello).由于涉及回调,我使用bind来确保每个方法中的'this'引用该对象.
pretendThingConstructor = function (greeting) {
this.greeting = greeting;
this.SayHello = function() {
console.log(this.greeting); // Works
};
this.WaitAndSayHello = function() {
setTimeout(function() {
console.log(this)
this.SayHello() // Fails
}, 500);
}
this.WaitAndSayHello.bind(this); // This bind() doesn't seem to work
}
var pretend_thing = new pretendThingConstructor('hello world');
pretend_thing.SayHello();
pretend_thing.WaitAndSayHello();
Run Code Online (Sandbox Code Playgroud)
代码打印'hello world',然后第二次'对象#没有方法'SayHello'失败.我可以从console.log中看到'this'指的是事件.但是不应该使用bind()修复此问题?
如何使bind()工作?
另外,我想干净利落地做到这一点:即,不要在多个地方引用对象的名称.
我正在努力将单页应用程序转换为backbone.JS.下面的视图使用body标签作为tagName - 即,我希望视图占用页面的整个内容.我不想使用容器div或其他黑客.
var ThingView = Backbone.View.extend({
tagName : "body",
...
// Show the HTML for the view
render : function() {
console.log('Displaying thing')
$(this.el).append('<h1>test</h1>');
console.log('finished')
console.log($(this.el))
return this; // For chaining
Run Code Online (Sandbox Code Playgroud)
渲染时,我明白了
finished
[
<body>?
<h1>?test?</h1>?
</body>?
]
Run Code Online (Sandbox Code Playgroud)
但是在我检查DOM之后,身体不再有文本了.
简单地说,我正在寻找一种在highcharts/highstocks中设置两个或更多plotLines的方法.API文档很好地展示了如何设置一个,尽管我不确定是否有办法设置其中两个.
内联,对象文字'get function()'样式和Object.defineProperty之间的功能似乎有重叠.
MDN docs for get https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/get没有提到内联'get'函数已被弃用.
var john = {
firstName: 'John',
lastName: 'Smith',
age: 21,
gender: 'Male'
// () ? String
// Returns the full name of object.
get name() {
return this.firstName + ' ' + this.lastName
},
// (new_name:String) ? undefined
// Sets the name components of the object,
// from a full name.
set name(new_name) {
var names = new_name.trim().split(/\s+/)
this.firstName = names['0'] || ''
this.lastName = names['1'] || ''
},
}
Run Code Online (Sandbox Code Playgroud)
Mozilla的Jeff Walden在2010年(似乎是)的文章中说: …
javascript properties getter-setter ecmascript-5 defineproperty
我有一个thunk名为logInline(改编自Co文档).
我注意到thunkified get总是似乎是yield一个数组.这是设计的吗?它是这样thunkify做的,还是标准的一部分yield?
var co = require('co'),
get = thunkify(request.get);
var logInline = co(function *(){
var google = yield get('http://google.com');
console.log(google[0].statusCode);
})
logInline()
Run Code Online (Sandbox Code Playgroud)
请注意,此处的变量'google'始终是一个数组.为什么?请注意,request.get通常返回err, response(即没有数组).
脚本BTW返回200google.com返回的任何其他响应代码.
唉产量文件是相当稀疏ATM.
编辑: Thunk并不总是返回数组.例如,如果var readFile = thunkify(fs.readFile);:
var fileContents = yield readFile('myfile', 'utf8');
log(fileContents);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,fileContents不会在数组中返回.那么为什么谷歌在一个阵列里? 在thunkify中似乎有一些东西可以控制thunk返回的内容
我该如何使用debug?阅读调试文档我得到:
通过调试,您只需调用导出的函数来生成调试函数,向其传递一个名称,该名称将确定是否返回 noop 函数,或者一个修饰的 console.error,因此您使用的所有控制台格式字符串都可以正常工作。
好的,调试模块导出单个函数,我明白了。但这部分似乎缺少一些东西:
“该函数采用 aname来确定是否返回 noop 函数,或者返回修饰的 console.error”
好的。我收集的name是一个字符串,那么什么字符串值决定是否返回无操作或修饰的console.error?我想要控制台错误,因为无操作似乎是默认值。
我有一个使用调试的模块。目前的设置如下;
var debug = require('debug')('module-name');
Run Code Online (Sandbox Code Playgroud)
而且非常安静。我想打开调试。我应该使用什么字符串值来启用调试?
我有两个测试套件(我使用的是mocha的TDD UI,它使用的suite()是test()而不是describe()和it()):
suite('first suite'), function(){
....
})
suite('second suite', function(){
beforeEach(function(done){
console.log('I SHOULD NOT BE RUN')
this.timeout(5 * 1000);
deleteTestAccount(ordering, function(err){
done(err)
})
})
...
}()
Run Code Online (Sandbox Code Playgroud)
运行mocha -g 'first suite仅从第一个套件运行测试,但运行beforeEach,I SHOULD NOT BE RUN在控制台上打印.
如何才能beforeEach()在其包含的套件中进行唯一的运行?
注意:我可以解决以下问题:
beforeEach(function(done){
this.timeout(5 * 1000);
if ( this.currentTest.fullTitle().includes('second suite') ) {
deleteTestAccount(ordering, function(err){
done(err)
})
} else {
done(null)
}
})
Run Code Online (Sandbox Code Playgroud) 我试图理解一些有一种新颖的承诺方法的代码:
var sequence = Promise.resolve();
sequence = sequence.then(
function() {
// success function
}
);
sequence = sequence.then(
function(keyPair) {
// success function
},
function(err) {
// err function
}
);
sequence = sequence.then(
function(keyPair) {
// success function
},
function(err) {
// err function
}
);
Run Code Online (Sandbox Code Playgroud)
这与正常的链式.then方法有何不同?使用安全吗?
因此,在 Visual Studio Code 中,我定义了.vscode/settings.json一些不显示的目录。
我有一些node_modules特定于我的项目并在我的存储库中维护的内容。它们都以 开始mycompany。我想在 VSCode 中显示这些,而不是其他。
这是我到目前为止所掌握的内容.vscode/settings.json:
{
// From http://stackoverflow.com/questions/33258543/how-can-i-exclude-a-directory-from-visual-studio-code-explore-tab
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/.vscode": true,
"**/.sass-cache": true,
"node_modules/mycompany**": false, // Hoping this will override next line
"node_modules/**": true
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试交换最后两行的顺序,但这也不起作用。如何忽略目录中的所有文件,除非它们以特定字符集开头?
javascript ×6
node.js ×3
.net ×1
backbone.js ×1
bind ×1
c# ×1
co ×1
ecmascript-5 ×1
es6-promise ×1
flow-control ×1
highcharts ×1
highstock ×1
methods ×1
mocha.js ×1
node-modules ×1
oop ×1
promise ×1
properties ×1
singlepage ×1
thunk ×1
yield ×1