I am a newbie in coffeescript. The following file main.js is generated after I include my coffeescript file functions.coffee:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
require('../../modules/common/frontend/functions');
},{"../../modules/common/frontend/functions":2}],2:[function(require,module,exports){
//Link selection in menu
function setCurrentlink(){
var currenturl=window.location.href;
var part=currenturl.match(/\n\/displaywizard\/(.*)$/g);
alert(part);
}
...
},{}]},{},[1])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2sv...
I have been trying to call the function setCurrentlink from html file as:
<script type="text/javascript">setCurrentlink();</script>
I tried putting the link to the js file in head section, at the bottom of the page but I am getting an error saying 'Can't find variable setCurrentlink'. Please help me find my mistake or anything I missed.
functions.coffee
#@export functions
#Link selection in menu
setCurrentlink = ->
currenturl = window.location.href
part = currenturl.match(/\n\/displaywizard\/(.*)$/g)
alert currenturl
return
...
Your function is defined within a function, so it's scope is limited to that function. You would need your function defined globally for this to work. That said, you're likely going about this the wrong way. If I had more info about what you're trying to accomplish I can advise a bit further.