我想知道最优雅的(和表演的?)模式,将我经常编写的代码替换为:
names = []
for person in persons:
names.append(person.GetName())
我写这篇文章是因为这是我用JavaScript写它的方式,我不知道还有什么更好的。但是我想我可以用列表理解来做一些事情?
我想要操作段落中的文本,并将它的上下文传递给我可以操作它的组件。基本上我想这样做:
HTML文件
<p bind="text"> Some text here </p>
Typescript文件
export class Example{
@bindable text;
constructor()
{
this.Function()
}
Function() {
console.log(text)
//Here i want to be printed out Some text here
本机javascript:
var Person;
Person = Backbone.Model.extend({});
如果我用google chrome控制台var person = new Person;编写,这段代码运行良好。
我的main.coffee
Person = Backbone.Model.extend({})
生成的main.js
// Generated by CoffeeScript 1.4.0
(function() {
var Person;
Person = Backbone.Model.extend({});
}).call(this);
如果我
我刚从用vb写代码转到用c#写,所以我有很多东西要跟上,请在这一点上帮助我。
我在aspx页面上有一个javascript函数,我想从后端触发该函数。
下面是我在后台的代码。
ScriptManager.RegisterStartupScript(this, this.GetType(), "closeScript", "showMessage('test')", true);
不幸的是,我得到了如下错误。
Error 30 Keyword 'this' is not valid in a static property,
好吧,这个问题可能会让javascript的厌恶者和铁杆开发者感到震惊,请原谅!
我喜欢用javascript编写回调函数的方式。
var on = function(isTrue, doThis) {if (isTrue) doThis();}
有没有可能在C中复制同样的想法?我知道它依赖于类型。这就是我的情况:
我有多个布尔值和多个过滤器,所以我的用法是,而不是写
if (thisIs == true) executeThisVoid(passingThisStruct)
我很乐意这样写:
on(thisIs, function(struct){ do this and this})
或者