本文介绍了从另一个带有nodejs的CoffeeScript文件中请求CoffeeScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道你是否能够在另一个咖啡杯中要求咖啡。
我的文件user.coffee的示例代码
UserObj
构造函数:(@name) - >
console.log @name
我的主档案范例程式
require./user.coffee
User = new UserObjExample
这可能是从coffeescript文件还是js文件?
解决方案是的。
user.coffee:
exports.UserObj =
class UserObj
constructor:(@name) - >
console.log @name
main.coffee:
<$ c $ p>{UserObj} = require./user
User = new UserObjExample
I was wondering if you are able to require a coffeescript from within another coffeescript.
My example code from file "user.coffee"
class UserObj
constructor: (@name) ->
console.log @name
My example code from main file
require "./user.coffee"
User = new UserObj "Example"
Is this possible from within a coffeescript file or just a js file?
解决方案
Yes it is possible.
user.coffee:
exports.UserObj =
class UserObj
constructor: (@name) ->
console.log @name
main.coffee:
{UserObj} = require "./user"
User = new UserObj "Example"
这篇关于从另一个带有nodejs的CoffeeScript文件中请求CoffeeScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!