[I've been getting undefined error and I dont know how to fix it.
Here's my code]1
You have Typo in your code
The function you have defined in js.js file is clacDollar
And the function you are calling in 6.html is calcDollar
if you use calcDollar instead of clacDollar in your code is better ..
try using
function calcDollar () {
in your definition
Related
I am attempting to eval a js file which has the following content:
let typeCache = {};
export function type(label = '') {
if (typeCache[label]) {
throw new Error(`Action type "${label}" is not unique"`);
}
typeCache[label] = true;
return label;
}
That's the whole file. No imports, nothing too fancy. But I'm getting an error that says ReferenceError: label is not defined. Which is strange, given that label seems defined just fine.
Can anyone spot anything wrong here?
UPDATE: This file (and many others) are generated from Typescript, and sent to gulp-template so that variables can be replaced, etc. That's when the code is evaled. Here is the complete stacktrace I'm getting:
ReferenceError: label is not defined
at eval (lodash.templateSources[80]:9:10)
at DestroyableTransform._transform (C:\Work\School\Frontend\node_modules\gulp-template\index.js:24:40)
at DestroyableTransform.Transform._read (C:\Work\School\Frontend\node_modules\readable-stream\lib\_stream_transform.js:159:10)
at DestroyableTransform.Readable.read (C:\Work\School\Frontend\node_modules\readable-stream\lib\_stream_readable.js:365:10)
at flow (C:\Work\School\Frontend\node_modules\readable-stream\lib\_stream_readable.js:739:34)
at DestroyableTransform.<anonymous> (C:\Work\School\Frontend\node_modules\readable-stream\lib\_stream_readable.js:610:7)
at emitNone (events.js:86:13)
at DestroyableTransform.emit (events.js:185:7)
at onwriteDrain (C:\Work\School\Frontend\node_modules\gulp\node_modules\readable-stream\lib\_stream_writable.js:300:12)
at afterWrite (C:\Work\School\Frontend\node_modules\gulp\node_modules\readable-stream\lib\_stream_writable.js:288:5)
at onwrite (C:\Work\School\Frontend\node_modules\gulp\node_modules\readable-stream\lib\_stream_writable.js:281:7)
Thanks!
Ohhh I found the issue.
The code above is sent to gulp-template, which uses Lodash's template function, which in turn also attempts to replace that ${label} in the function... resulting in the error given that this is not defined at that time.
So, beware my gulp-template friends.
I fixed my issue by disabling gulp-template's ES6 interpolation and leaving just the ERB style interpolation (e.g. <% blah %>). I did that by providing an options object along with the template, like so:
.pipe(plugins.template(templateToReplace, { interpolate: /<%=([\s\S]+?)%>/g }))
I want to write an jquery function because otherwise I have to write some code over and over.
Here is wat the function was first:
$(".checkbox-car").click(function(){
$(this).toggleClass('checked-car')
});
$(".checkbox-bus").click(function(){
$(this).toggleClass('checked-bus')
});
And this is what I tried to do with my own function:
$.fn.checkedFunction = function(Clicked, Checked){
$(this).click(function(){
console.log('check');
$(Clicked).toggleClass(Checked);
});
}
$('.checkbox-car').checkedFunction('.checkbox-car','.checked-car');
But I get the error that the checkedFunction is not defined.
What am I doing wrong here can someone help me out?
You're getting an error that checkedFunction isn't defined because it isn't. checkedFunction is a property defined in$.fn object.
To use the function you created, you should do
$(".some-element").checkedFunction(...args).
More over, you should read the jQuery docs.
Just had to do this:
$.fn.checkedFunction = function(Clicked, Checked){
$(this).click(function(){
$(Clicked).toggleClass(Checked);
});
}
$('.checkbox-car').checkedFunction('.checkbox-car','checked-car');
$('.checkbox-bus').checkedFunction('.checkbox-bus','checked-bus');
remove the dot before the second checked- class
I have a module "./lib/common.js", like this:
function foo(text){
console.log(text);
}
function boo(text){
console.log(text);
}
module.exports=foo;
module.exports=boo;
I'm trying to include these functions in another js file using browserify :
var common =require('./lib/common.js');
$(document).ready(function() {
common.foo('hi');
});
Browserify creates the bundle,but on the browser I get
Uncaught TypeError: common.foo is not a function
Ok this was very stupid, I was overwriting my module.exports with the last row module.exports=boo;
With this change it works:
module.export.foo=foo;
module.export.boo=boo;
I'm trying to get my head around require in simple web applications. I've got everything working fairly well until I try to execute some code inside a 'define' block;
define(['jquery'], function() {
var Playlist = function() {
// bunch of helper code here
};
return Playlist;
});
If i comment out the define wrapper the code works perfectly, but something I'm doing wrong here is causing 'Uncaught ReferenceError: Playlist is not defined'.
What am I missing about 'define' in AMD?
Try
define(['jquery'], function($) {
var Playlist = function() {
// bunch of helper code here
};
return Playlist;
});
And when will you get the Uncaught ReferenceError: Playlist is not defined error? Because Playlist is in your callback function and you can not use it outside of course.
quick question,why this don`t work and how to fix it
$("#Button").click(function(){
count++;
var b=new Button(count);
b.render();
$("#div"+ count).dblclick(function(){
var diva=this;
$(this).append("<span id='colorchange'><input type='color' id='color' onchange='func("+diva+")' name='favcolor'></span>");
});
});
function func(diva){
alert(diva);
}
i`m getting error Uncaught SyntaxError: Unexpected identifier
You can add jquery library "http://code.jquery.com/jquery-1.9.1.js",
and Button is not recognized unless you defined it anywhere...
You can get help from "http://sideroad.secret.jp/plugins/jQueryRender/"