在 Visual Studio 2010 中使用从 Mindscape Web Workbench(coffeescript 源)生成的 javascript
此咖啡脚本代码
class TestCoffee
constructor: (@saludo) ->
helloCoffee: ->
alert @saludo+" Coffee v7"
使用 Mindscape Web Workbench 2.0.332.18684 生成以下 javascript:
(function() {
var TestCoffee;
TestCoffee = (function() {
function TestCoffee(saludo) {
this.saludo = saludo;
}
TestCoffee.prototype.helloCoffee = function() {
return alert(this.saludo + " Coffee v7");
};
return TestCoffee;
})();
}).call(this);
我应该如何在我的 asp.net mvc 3 视图中使用此代码?
我正在导入 js 代码
<script src="@Url.Content("~/Scripts/helloCoffe.js")" type="text/javascript"></script>
并尝试使用 with
<script type="text/javascript">
$(document).ready(function () {
var coffee;
coffee = TestCoffee("Jelouuuu");
coffee.helloCoffee();
});
</script>
我收到了 TestCoffee 未定义错误
那么,我应该如何使用它?
提前致谢!
This coffee script code
class TestCoffee
constructor: (@saludo) ->
helloCoffee: ->
alert @saludo+" Coffee v7"
is generating the following javascript with mindscape web workbench 2.0.332.18684
(function() {
var TestCoffee;
TestCoffee = (function() {
function TestCoffee(saludo) {
this.saludo = saludo;
}
TestCoffee.prototype.helloCoffee = function() {
return alert(this.saludo + " Coffee v7");
};
return TestCoffee;
})();
}).call(this);
How should I use this code inside my asp.net mvc 3 view?
I'm importing the js code with
<script src="@Url.Content("~/Scripts/helloCoffe.js")" type="text/javascript"></script>
and trying to use with
<script type="text/javascript">
$(document).ready(function () {
var coffee;
coffee = TestCoffee("Jelouuuu");
coffee.helloCoffee();
});
</script>
I got a TestCoffee undefined error
So, how should I use it?
Thanks In Advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是设计使然:
http://jashkenas.github.com/coffee-script/
我通常使用 jQuery $ .extend 将函数推送到 jquery 命名空间中以供其他脚本使用。
IE:
file1.coffee
file2.coffee
This is by design:
http://jashkenas.github.com/coffee-script/
I normally use jQuery $.extend to push a function into the jquery namespace for other scripts to use.
IE:
file1.coffee
file2.coffee
简单的改变就能让它发挥作用。在类声明中添加“@”符号:
并更改实例化类的方式。在你的课堂上使用“新”
应该可以得到你想要的。
Simple changes will allow this to work. Add a '@' symbol to your class declaration:
And change the way you instantiate your class. Use a 'new' on your class
That should get you what you want.