作品
Template.Hello.onRendered(function() {
this.autorun(() => {
console.log('sup');
});
});
Run Code Online (Sandbox Code Playgroud)
不行.
Template.Hello.onRendered(() => {
this.autorun(() => {
console.log('sup');
});
});
Run Code Online (Sandbox Code Playgroud)
错误是TypeError:_this.autorun不是函数.
使用箭头符号的任何想法都会给我们这个错误?
我有一个prototype
写在Array
类上的函数,比如
Array.prototype.myfunc = () =>
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
当我在一个数组上调用它时,身体this
指window
的是
var result = [1, 69, -1, 1].myfunc();
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它引用它被调用的数组?
export default async function () {
};
Run Code Online (Sandbox Code Playgroud)
要么
export default async () => {
};
Run Code Online (Sandbox Code Playgroud)
导出默认函数时首选哪一个?为什么?
我有一个非常奇怪的问题.我只想选择一个被点击的元素.我做了很多次,它总是工作,但这次,jQuery $(this)选择器不选择被点击的元素,它选择窗口对象.请让我知道,如果你有一个想法,可能是什么原因.我使用的是jQuery 2.1.4和Twitters Bootstrap 3.3.5
HTML:
<a class="btn btn-danger btn-xs delete-file"><i class="fa fa-trash" aria-hidden="true"></i> Löschen</a>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(document).ready( () => {
$('.delete-file').on('click', () => {
let element = $(this);
console.log(element);
});
});
Run Code Online (Sandbox Code Playgroud)
控制台输出:
n.fn.init [Window]
Run Code Online (Sandbox Code Playgroud)
代替:
n.fn.init [a.btn.btn-danger.btn-xs.delete-file]
Run Code Online (Sandbox Code Playgroud)
先感谢您!
我有一个Map
对象:
let dateJobMap = new Map();
for (let jobInArray of this.state.jobs) {
let deliveryDate: Date = new Date(jobInArray.DeliveryDate);
let deliveryDateString: string = deliveryDate.toLocaleDateString("en-US");
if (dateJobMap.has(deliveryDateString)) {
let jobsForDate: IDeliveryJob[] = dateJobMap.get(deliveryDateString);
jobsForDate.push(jobInArray);
}
else {
let jobsForDate: IDeliveryJob[] = [jobInArray];
dateJobMap.set(deliveryDateString, jobsForDate);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的render
方法中,我想为值数组中的每个传递作业调用TruckJobComp对象以显示它:
<div className={ styles.column }>
<p className={ styles.description }>{escape(this.props.description)}</p>
{
dateJobMap.forEach(function(jobsForDate, dateString) {
jobsForDate.map(job => (
<TruckJobComp job = { job } />
))
})
}
</div>
Run Code Online (Sandbox Code Playgroud)
这似乎应该起作用,但不起作用。它从不创建TruckJobComp。我做了.forEach
我的迭代Map
,并为每个 …
我已经使用 Axios 发出了一个 get 请求,它按预期返回了一些数据,但我无法在挂载的函数中访问应用程序的数据属性来分配请求的结果。控制台日志this.productList
返回undefined
. 任何人都可以指出我正确的方向吗?
new Vue({
el: '#products',
data: function(){
return{
test: 'Hello',
productList: null
}
},
mounted: function(){
axios.get('https://api.coindesk.com/v1/bpi/currentprice.json').then(function(response){
console.log(response.data);
console.log(this.productList)
}).catch(function(error){
console.log(error);
})
}
})
Run Code Online (Sandbox Code Playgroud) 我有一个包含以下代码的文件:
class Animal {
doSomething = () => {
return 'Hi.';
};
}
class Dog extends Animal {
doSomething = () => {
return super.doSomething() + ' Woof!';
};
}
console.log(new Dog().doSomething());
Run Code Online (Sandbox Code Playgroud)
注意:尝试运行上面的代码片段可能不起作用,因为我不知道如何让它使用我的 Babal 设置。
无论如何,当我使用 Babel 编译它并在 Node 中运行它时,我收到以下错误:
/Users/elias/src/classFieldTest/build/classFieldTest.js:15
return super.doSomething() + ' Woof!';
^
TypeError: (intermediate value).doSomething is not a function
at Dog.doSomething (/Users/elias/src/classFieldTest/build/classFieldTest.js:15:26)
at Object.<anonymous> (/Users/elias/src/classFieldTest/build/classFieldTest.js:21:23)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup …
Run Code Online (Sandbox Code Playgroud) javascript babeljs arrow-functions ecmascript-next class-fields
var mySelf = {
name: "dina",
job: "Programmer",
yearOfBirth: 1993,
age: () => 2019 - this.yearOfBirth
};
let result = mySelf.age();
console.log(result);
Run Code Online (Sandbox Code Playgroud)
结果是 NaN
请帮帮我实际发生了什么?
我使用以下包装器代理方法:
public static wrap(target) {
function construct(constructor, args) {
const c: any = function(this) {
return constructor.apply(this, args);
};
c.prototype = constructor.prototype;
return new c();
}
const f = (...args) => {
const instance = construct(target, args);
const descriptors = getMethodDescriptors(target, instance);
return new Proxy<T>(
instance,
new SomeProxyHandler(descriptors)
);
};
f.prototype = target.prototype;
return f;
}
Run Code Online (Sandbox Code Playgroud)
这在包装编译到ES5的类时运行良好但是现在我试图以ES6为目标我在constructor.apply(this, args)
说:
TypeError: Class constructor OneOfMyClasses cannot be invoked without 'new'
Run Code Online (Sandbox Code Playgroud)
如何修复此代码,以便wrap
代理任何JavaScript目标的类并维护正确的原型链?
两者的任务是不同的。两者之间有区别还是相等?
第一的
onClick(){
return (
<div></div>
)
}
Run Code Online (Sandbox Code Playgroud)
第二
const onClick= ()=> {
return(
<div></div>
)
}
Run Code Online (Sandbox Code Playgroud) javascript ×9
ecmascript-6 ×2
reactjs ×2
async-await ×1
axios ×1
babeljs ×1
class-fields ×1
es6-modules ×1
jquery ×1
meteor ×1
node.js ×1
proxy ×1
this ×1
typescript ×1
vue.js ×1
vuejs2 ×1