我的腳本尖銳操作正在重命名,因此它們的前綴是下劃線。儘管代碼在瀏覽器中運行得非常好,但是要記住添加下劃線來使用它的客戶端是非常煩人的。這是否是設計的,是否有改變它的方法?ScriptSharp(腳本#)和敲除
這裏是一個樣本: 我已經轉載 - Knockout JS的教程示例「點擊計數器」。
腳本夏普視圖模型(C#代碼):
public sealed class ClickCounterViewModel
{
public Observable<int> numberOfClicks;
//Dependent Observable is now called computed but is backward compat.
public DependentObservable<bool> hasClickedTooManyTimes;
//WARNING - this get converted to _registerClick Client Side - not sure why.
Action registerClick;
Action resetClicks;
public ClickCounterViewModel()
{
numberOfClicks = Knockout.Observable<int>(0);
registerClick = delegate() {
this.numberOfClicks.SetValue(this.numberOfClicks.GetValue() + 1);
};
resetClicks = delegate() { this.numberOfClicks.SetValue(0); };
DependentObservableOptions<bool> options = new DependentObservableOptions<bool>();
options.Model = this;
options.GetValueFunction = new Func<bool>(delegate {
return this.numberOfClicks.GetValue() >= 3;
});
hasClickedTooManyTimes = Knockout.DependentObservable<bool>(options);
}
}
當這個代碼轉換爲JavaScript的行動得到前綴爲下劃線。這是預期的行爲嗎?
生成的代碼(JavaScript)的 - 只是顯示生成的註釋來說明這個問題:
Knockout2Example2.ClickCounterViewModel = function Knockout2Example2_ClickCounterViewModel() {
/// <field name="numberOfClicks" type="Observable`1">
/// </field>
/// <field name="hasClickedTooManyTimes" type="DependentObservable`1">
/// </field>
/// <field name="_registerClick" type="Function">
/// </field>
/// <field name="_resetClicks" type="Function">
/// </field>
/// This script was generated using Script# v0.7.4.0