|
Because the return statement at the end of the home function creates a copy of the value of the count variable at the point where the method returns. There is no connection between that copy and the local variable, so when the "work" functions update the local variable, that change is not reflected in the returned object.
Imagine how difficult it would be to write code in a language where that was not the case!
var x = 42;
var y = x;
x = 0;
You'll need to change the returned object so that count is a function that returns the current value of the local variable:
var home = function() {
...
return {
caller: caller,
count: function(){
return count;
}
};
};
var h = home();
h.caller().job1();
h.caller().job2();
h.caller().job1();
console.log(h.count());
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There is a bug somewhere in this function and I can't find where. Please advise.
function verifyCrops() {
try {
for(var i = 0; i < 7; i++) {
if (cropsFieldset.getElementsByTagName("input")[i].
checked) {
cropsComplete = true;
messageElement.innerHTML = "";
testFormCompleteness();
i = 8;
}
}
if (i === 7) {
throw "Please select at least one crop."
}
}
catch(message) {
cropsComplete = false;
messageHeadElement.innerHTML = ""
messageElement.innerHTML = message;
}
}
modified 3-Oct-17 23:26pm.
|
|
|
|
|
Dunno, but it's poor form to catch what you throw yourself.
|
|
|
|
|
Jason Lemon wrote: There is a bug somewhere in this function How do you know?
|
|
|
|
|
Place a debugger and execute line by line and see in which line the error is being thrown
|
|
|
|
|
How could we possibly know? We don't know what the code is supposed to do nor can we run it. We don't even have all of the code. Is this a joke or did you really expect someone to be able to tell you?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Please let us know what the function is expected to do, and what it does not!
|
|
|
|
|
Hi Guys! Can anyone help me with my web project? My project is Online Bus Ticketing System. I do not know where to begin. I need to create a Online Bus Ticketing System with only use of Html/Css and Javascript. Yes, No Database allowed and no PHP. I dont know what to do.
mnrddcls
|
|
|
|
|
Member 13441948 wrote: I dont know what to do. Use Google to find tutorials and samples on HTML, CSS, PHP etc. A good place to start would be W3Schools Online Web Tutorials[^].
|
|
|
|
|
I used code project articles for to learn stuff in college. But when you don't find what you need, you can always google.
|
|
|
|
|
without database how will you read/write the data?
using any API?
|
|
|
|
|
Hey guys!
Im in a bit of a pickle.
Im supposed to hand in an assignment where i will use the arrows on the keyboard to make a rectangle move.
I cant figure out how to do it. My teacher wont respond to my messages. Im hoping you guys can help me or point me in the right direction. Code is included below.
Thanks!
window.onload=function() {
var canvas=document.getElementById('myCanvas');
context= canvas.getContext('2d');
context.fillStyle="#FF0000";
context.fillRect(0,0,75,50);
var rect=new Object();
rect.x=0;
rect.y=0;
rect.moveright=function(){rect.x++;}
rect.draw=function(){
rect.x
rect.y
}
document.onkeydown=function(e){
if(e.keyCode=="39"){
rect.erase();
rect.moveright();
rect.draw();
}
if(e.keyCode=="37"){
rect.erase();
rect.moveleft();
rect.draw();
}
if(e.keyCode=="40"){
rect.erase();
rect.movedown();
rect.draw();
}
if(e.keyCode=="38"){
rect.erase();
rect.moveup();
rect.draw();
}
}
};
|
|
|
|
|
What is your question?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Hi,
I am new to Angular js and I was trying to find out proven ways to upgrade an existing Angular 1 app to Angular 4.
What I wish to do is to be able to run the angular 1 and angular 4 components together since I do not want to migrate all at once and proceed gradually.
It will be a great help if some could point me in the right direction.
I am not the one who knocks. I never knock.
In fact, I hate knocking.
|
|
|
|
|
Hi GKP1992. I'm sorry your question has been dangling this long.
I don't know that what you're asking is really possible; Angular is pretty adverse to multiple instancing, as in it won't do it. Angular 1 business objects and Angular 2+ components are basically analogues of each other, but there is exactly zero compatibility between the two. You might be able to find shims on the interwebs, but it's not something I can make any solid suggestions about.
I'd love to help, as a former advocate for Angular 1, but the whole Angular 2/4 fiasco and the new ostensibly enforced development pipeline (NPM, Typescript, etc) has definitely cooled me on the framework and driven me to evaluate other frameworks to manage my bindings (I like RiotJS lately, since it's basically just a binding tool driven by Vanilla JS). I strongly suspect that I'm not alone in this regard.
My advice would be to start evaluating other things in the field and separating yourself from a technology whose development team has lost sight of that technologies purpose. There are many.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks for the response Nathan. I have realized how difficult it can be to achieve what I am trying to.
I looked at the ng-upgrade module and this controversial method of ng migration. Anyways, we have decided to upgrade all the project at once.
It can be a PITA, but that's the price we pay for a hot tech.
I am not the one who knocks. I never knock.
In fact, I hate knocking.
|
|
|
|
|
var my_name_is = 'This is global!';
function f() {
var my_name_is = 'This is local to f()';
function print_name() {
var print_name = 'This is local to print_name()';
console.log(this.print_name);
}
print_name();
}
function print_name() is an inner function of fucntion f();
In the above function,if function f() belongs to Window Object,then to what object function print_name() belongs to?
|
|
|
|
|
Every time you call f, it create a temporary function called print_name, execute it and then get rid off it. Still belongs to function f; on the other hand f belongs to window. f stays there as long as window is alive
I do not fear of failure. I fear of giving up out of frustration.
|
|
|
|
|
hello everyone.
i'm here to share and actually maybe to get a pro assistance about an alternative to confirm that i made.
ok. the problem is that "confirm" is not compatible with my web site's style. so i thought that maybe there is a way to make a confirm box with css. i design a box with w3css. and i loved it.
here is the code:
<div id="msgBox" class="w3-modal">
<div class="w3-modal-content w3-card-4 w3-animate-top w3-light-gray w3-border w3-border-black" style="max-width: 600px;">
<header class="w3-bar w3-black">
<div class="w3-bar-item" id="msgBoxCaption"></div>
<span onclick="document.getElementById('msgBox').style.display='none'" class="w3-bar-item w3-button w3-hover-red w3-display-topright" title="Close">×</span>
</header>
<div class="w3-container w3-padding-16" id="msgBoxMessage">
</div>
<footer class="w3-container w3-gray w3-border-top w3-border-black w3-padding-16 w3-right-align" id="msgBoxButtons">
</footer>
</div>
</div>
and a function to fill the fields and create buttons and of course show it:
function msgBoxModal(caption, message, buttons = ['Close'], buttonscmd =
["document.getElementById('msgBox').style.display='none'"])
{
window.parent.document.getElementById('msgBoxCaption').innerHTML = '<b>'+ caption + '</b>';
window.parent.document.getElementById('msgBoxMessage').innerText = message;
btnNode = window.parent.document.getElementById('msgBoxButtons');
while (btnNode.firstChild) {
btnNode.removeChild(btnNode.firstChild);
}
for(var i = 0; i < buttons.length; i++) {
newButton = window.parent.document.createElement('button');
if (typeof buttonscmd[i] == 'undefined') { buttonscmd[i] = "document.getElementById('msgBox').style.display='none'"; }
if (buttonscmd[i] != "document.getElementById('msgBox').style.display='none'") { buttonscmd[i] += ";document.getElementById('msgBox').style.display='none'"; }
newButton.setAttribute('onclick', buttonscmd[i]);
newButton.classList.add('w3-button', 'w3-blue-gray', 'w3-hover-green', 'w3-margin-left');
newButton.setAttribute('name', 'button' + i);
newButton.innerText = buttons[i];
btnNode.appendChild(newButton);
}
window.parent.document.getElementById('msgBox').style.display = 'block';
}
calling from javascript:
btnCmd = "window.frames['I1'].document.getElementById('hdnDelSubmit').setAttribute('value', 'yes');";
btnCmd += "window.frames['I1'].document.getElementById('frmRefs').submit()"
msgBoxModal('Delete', 'Are you sure you want to delete the selected items? This action can not be undone!', ['Yes', 'No'], [btnCmd]);
and maybe from php:
function jsAlert($jsCaption, $jsMsg)
{
echo "<script type='text/javascript'>msgBoxModal('$jsCaption', '$jsMsg');</script>";
}
jsAlert('It Works!', 'Hello World!');
modified 13-Sep-17 4:47am.
|
|
|
|
|
Did you have a question?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
how connect data base connection in asp.net and back end sql server..
|
|
|
|
|
|
Connect to what? Do you want to get data in C#? Do you want to bind a control? You need to give a lot more details.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Also, why did you post this in JavaScript? You are asking a sql, c#, and asp.net question. Should have put it in asp.net.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|