JavaScript - Inheritance And Function Overriding Question
Hi!
This is probably a classic inheritance thing... I have two objects, C1 and C2. Both contains a callback method named 'callback'. Now, if I let C2 inherit from C1, then C1's 'callback' gets overridden by C2's. The problem is I still want C1's methods to access their own 'callback' method. Is this possible, and is it "valid"? Am I headed down disaster lane here? Should I re-think and refactor? Example: Code: function C1 () {}; C1.prototype.callback = function () { console.log('c1 called'); }; C1.prototype.call = function () { //do stuff this.callback(); }; function C2 () {}; C2.prototype = new C1(); C2.prototype.callback = function () { console.log('c2 called'); }; var obj = new C2(); obj.call(); Output: c2 called Regards Don Similar TutorialsWhat are the benefits of prototypal inheritance over classical inheritance?
What are the benefits of prototypal inheritance over classical inheritance?
I have a menubar across the top of a page in a separate frame. Content loads into main frame below it. I'm adding an onClick menu option that I'd like to open in the same, full window, without the menubar frame on top. Any way to do this? Thx. I have a JavaScript drop down menu and just under it is the slide show also using JavaScript.Now when I you select the menu the drop down contents are hidden behind the slide underneath it .But if it is a still image,they appear on top of the image. I need the menu the drop down contents to appear on top on the slide show. How can I achieve that. Dear all, attached is a page for my website to allow visitors to purchase photos. It is made from 2 Paypal example scripts - one for the form and another for an additional text box. It works fine apart from one detail, the text being entered does not get sent - instead, the information it forwards is "6x4 Colour Prints. Item Number id10" The "6x4 Colour prints" bit is good - the "Item number id10" is where I'd ideally like to see the custom text being entered and the guys at Paypal developer forums have said that a Javascript command is overriding the text being forwarded and to seek advice from those who know Javascript. I've tried for a day by trial and error to see if I can take this command out but it has got to the hair pulling out stage so I'm calling on those who know best to cast a wise eye over the code and see if there is an easy fix to this. Any help or suggestions as to howe to alter this will be most gratefully received. Thanks in advance, Dave. Hello All, can someone pls help me with the error shown in firebug for the code below: Firebug error: Object.method is not a function Object.method('superior', function (name) { Constructor functions work until it gets to /* Super method template */. Thats where the error comes from. Code is from javascript - good parts. var mammal = function(spec) { var that = {}; that.get_name = function() { return spec.name; } that.says = function() { return spec.saying || ''; } return that; } var myMammal = mammal({name: 'Herbie', saying: 'Im herb the mammal'}); console.log(myMammal.get_name()); console.log(myMammal.says()); var cat = function(spec) { spec.saying = spec.saying || 'Meow!' var that = mammal(spec); that.purr = function(n) { var i, s = ''; for(i=0; i < n; i +=1) { if(s) { s += '-'; } s += 'r' } return s; } that.get_name =function() { return that.says() +' '+ spec.name +' '+ that.says(); } return that; } var myCat = cat({name: 'Henrietta!', saying: 'Im a pussycat'}) console.log(myCat.get_name()); console.log(myCat.purr(3)); /* Super method template */ Object.method('superior', function (name) { var that = this, method = that[name]; return function ( ) { return method.apply(that, arguments); }; }); /* Super method e.g. */ var coolcat = function (spec) { var that = cat(spec), super_get_name = that.superior('get_name'); that.get_name = function (n) { return 'like ' + super_get_name( ) + ' baby'; }; return that; }; var myCoolCat = coolcat({name: 'Bix'}); console.log(myCoolCat); var name = myCoolCat.get_name(); console.log(name); I'm trying my best to figure this out with google, but I've found 4 different syntaxes and can't get any of them to work. I need to have several classes extend another for my chess game. I need classes, Rook, Knight, Bishop etc... all extend from class Piece. can anyone help me with the syntax var Piece = Class.create(); Piece.prototype = { initialize: function(src, square){ //init stuff here }, setSqua function(square){ //sets the square of the piece }, } Rook.prototype = new Piece(); function Rook(src, square) { Piece.apply(src, square); } Thanks to anyone who helps Here is my webpage (don't laugh!). If you click on Espanol it translates the page to Spanish. English is set up differently and it works too. Please tell me why clicking Spanish works but not French, Portuguese, etc. Code: <body> <p align="center"> <b id='Spanish1'><b id='French1'><b id='Portuguese1'><b id='German1'><b id='Danish1'><b id='Dutch1'><b id='Finnish1'><b id='Swedish1'><b id='Norwegian1'></b>Change Language:</b></b></b></b></b></b></b></b> <input type='button' onclick='TranslateToSpanish()' value='Espanol' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToFrench()' value='Francais' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToPortuguese()' value='Portuguese' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToGerman()' value='Deutsch' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToDanish()' value='Dansk' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToDutch()' value='Nederlands' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToFinnish()' value='Suomi' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToSwedish()' value='Svensk' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToNorwegian()' value='Norske' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <a href='http://www.luxe-bux.com/the-link-of-the-same-page-viewer-is-on-so-it-will-refresh-the-page-back-to-english'><input type='button' value='English' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"></a> <div class="header" onclick="location.href='http://www.luxe-bux.com';" style="cursor: pointer"> <img src="http://i770.photobucket.com/albums/xx344/colorscolors123/0546d64a.png"> Luxe Bux <font size="2"><b id='Spanish2'><b id='French2'><b id='Portuguese2'><b id='German2'><b id='Danish2'><b id='Dutch2'><b id='Finnish2'><b id='Swedish2'><b id='Norwegian2'></b>Luxuries For Less!</b></b></b></b></b></b></b></b></b><br>.</font></div> <div class="test"> <div class="allthestuff"> <h1><!-- Atomz HTML for Search --> <form method="get" action="http://search.atomz.com/search/" rel="nofollow" target="foo" onSubmit="window.open('', 'foo', 'width=1200,height=500,status=yes,resizable=yes,scrollbars=yes')"> <input type="hidden" name="sp_a" value="sp1004432f"> <p align="center"><font color=ffffff size=3><b id='Spanish3'><b id='French3'><b id='Portuguese3'><b id='German3'><b id='Danish3'><b id='Dutch3'><b id='Finnish3'><b id='Swedish3'><b id='Norwegian3'>Search Luxe Bux:</b></b></b></b></b></b></b></b></b></font> <input size="30" name="sp_q" style="background-color: #cb672d; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Find it!"><b id='Spanish4'></b><b id='French4'></b> <input type="hidden" name="sp_p" value="all"> <input type="hidden" name="sp_f" value="UTF-8"></p> </form> </h1> <div class="container"> <ul> <li><a class="nav" href="http://www.luxe-bux.com"><b class="ShopNow"><b id='Spanish5'><b id='French5'><b id='Portuguese5'><b id='German5'><b id='Danish5'><b id='Dutch5'><b id='Finnish5'><b id='Swedish5'><b id='Norwegian5'>Shop Now!</b></b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish6'><b id='French6'><b id='Portuguese6'><b id='German6'><b id='Danish6'><b id='Dutch6'><b id='Finnish6'><b id='Swedish6'><b id='Norwegian6'>Reviews of Luxe Bux</b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish7'><b id='French7'><b id='Portuguese7'><b id='German7'><b id='Danish7'><b id='Dutch7'><b id='Finnish7'><b id='Swedish7'><b id='Norwegian7'>FAQ/Return Policy/More Info</b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish8'><b id='French8'><b id='Portuguese8'><b id='German8'><b id='Danish8'><b id='Dutch8'><b id='Finnish8'><b id='Swedish8'><b id='Norwegian8'>Contact</b></b></b></b></b></b></b></b></b></a></li> </ul> </div> <br> <div class="IdeaColor"> <div class="marginspacer"> <p><img alt="small-euro-currency-sign.jpg" style="padding: 15px; border: 2px solid #000000;" src="http://www.luxebux.com/sitebuildercontent/sitebuilderpictures/.pond/desaturated-and-resized-only.jpg.w180h269.jpg" align="right" vspace="0" hspace="5"></p> <p> <b id='Spanish9'><b id='French9'><b id='Portuguese9'><b id='German9'><b id='Danish9'><b id='Dutch9'><b id='Finnish9'><b id='Swedish9'><b id='Norwegian9'> <font size="4">Here's what our customers are saying...<br><br></font><br /><font size="3"> "THANK YOU VERY MUCH NICE DEALING WITH"<br> "Exceptional service overall and great care in packaging! I will buy again! A++"<br> "Exactly as advertised! Fast shipping(always takes longer to Canada) A+" <br> "great online sellers. highly recomended! will buy from again"<br> "Arrived in record time and packaged well. Thanks"<br> "Quick"<br> "Great service, very fast shipping. I will definitely buy from them again"<br> "Arrived quickly as described!!"<br><br><br><br><br><br></p> </b></b></b></b></b></b></b></b></b> </div></div> <table height="100"><tr><td></td></tr></table> <table width=100% height=20px bgcolor="#f5e9c3"> <tr><td></td></tr> </table> <script type="text/javascript"> function TranslateToSpanish() { document.getElementById('Spanish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Spanish2').innerHTML = 'Lujos para menos!'; document.getElementById('Spanish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Spanish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Spanish5').innerHTML = 'Tienda ahora!'; document.getElementById('Spanish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Spanish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Spanish8').innerHTML = 'Contacto'; document.getElementById('Spanish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p>'; } </script> <script type="text/javascript"> function TranslateToFrench() { document.getElementById('French1').innerHTML = 'Lengua del cambio:'; document.getElementById('French2').innerHTML = 'Lujos para menos!'; document.getElementById('French3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('French4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('French5').innerHTML = 'Tienda ahora!'; document.getElementById('French6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('French7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('French8').innerHTML = 'Contacto'; document.getElementById('French9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToPortuguese() { document.getElementById('Portuguese1').innerHTML = 'Lengua del cambio:'; document.getElementById('Portuguese2').innerHTML = 'Lujos para menos!'; document.getElementById('Portuguese3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Portuguese4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Portuguese5').innerHTML = 'Tienda ahora!'; document.getElementById('Portuguese6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Portuguese7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Portuguese8').innerHTML = 'Contacto'; document.getElementById('Portuguese9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToGerman() { document.getElementById('German1').innerHTML = 'Lengua del cambio:'; document.getElementById('German2').innerHTML = 'Lujos para menos!'; document.getElementById('German3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('German4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('German5').innerHTML = 'Tienda ahora!'; document.getElementById('German6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('German7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('German8').innerHTML = 'Contacto'; document.getElementById('German9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToDanish() { document.getElementById('Danish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Danish2').innerHTML = 'Lujos para menos!'; document.getElementById('Danish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Danish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Danish5').innerHTML = 'Tienda ahora!'; document.getElementById('Danish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Danish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Danish8').innerHTML = 'Contacto'; document.getElementById('Danish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToDutch() { document.getElementById('Dutch1').innerHTML = 'Lengua del cambio:'; document.getElementById('Dutch2').innerHTML = 'Lujos para menos!'; document.getElementById('Dutch3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Dutch4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Dutch5').innerHTML = 'Tienda ahora!'; document.getElementById('Dutch6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Dutch7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Dutch8').innerHTML = 'Contacto'; document.getElementById('Dutch9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToFinnish() { document.getElementById('Finnish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Finnish2').innerHTML = 'Lujos para menos!'; document.getElementById('Finnish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Finnish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Finnish5').innerHTML = 'Tienda ahora!'; document.getElementById('Finnish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Finnish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Finnish8').innerHTML = 'Contacto'; document.getElementById('Finnish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToSwedish() { document.getElementById('Swedish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Swedish2').innerHTML = 'Lujos para menos!'; document.getElementById('Swedish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Swedish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Swedish5').innerHTML = 'Tienda ahora!'; document.getElementById('Swedish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Swedish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Swedish8').innerHTML = 'Contacto'; document.getElementById('Swedish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToNorwegian() { document.getElementById('Norwegian1').innerHTML = 'Lengua del cambio:'; document.getElementById('Norwegian2').innerHTML = 'Lujos para menos!'; document.getElementById('Norwegian3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Norwegian4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Norwegian5').innerHTML = 'Tienda ahora!'; document.getElementById('Norwegian6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Norwegian7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Norwegian8').innerHTML = 'Contacto'; document.getElementById('Norwegian9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> </body></html> Hello I have a question which has been bugging me for a while now so have decided to ask it on CF. In PHP you can use the '&' symbol as a function operator for example like so. PHP Code: function demoFunc(&$output='') { for($i=1;$i<count(func_get_args());$i++) { $output .= ' '.func_get_arg($i); } $output = trim($output); } As you can see the '&' symbol was used in the argument section to allow the function to be used like this demoFunc($output,'hello','world'); print $output; My question is how can I do this in JavaScript to do the same thing like use the variable used in the function argument section and use it like it would be used in PHP? Thank you - DJCMBear $.fn.superfish = function(op) { } So I see here that a function is being declared and the name of the function is '$.fn.superfish'. Is there any special meaning at all behind the $ in this situation? I have a dice simulator. Basically, a user enters how many sides they want on their die, and then I digitally roll 2 of them. And produce the output in a document.writeln. I think I'm having trouble with the this.sides in the constructor function (in the head section). Also, I'm getting a syntax error in Safari : 25TypeError: 'null' is not an object (evaluating 'element.value') Am I not suppose to put the variable in the constructor function? Any help would be appreciated. <head> var element = document.getElementById("number"); var sides = element.value; function Die( ) { this.sides = sides; this.roll = function( ) { return parseInt((Math.random( ) * 1000) % this.sides) + 1; } } </script> </head> <body> <h1>Adam's Dice Rolling Game!</h1><br/> <form action="" method="post"> <p> <input type="text" name="number" id="number"/> </p> <p> <input type="button" value="Roll the dice!" id="roll_me"/> </p> </form> <script type="text/javascript"> var d = new Die( ); d.sides = sides; var rolled_value = d.roll( ); var r1 = document.getElementById( "roll_me" ); r1.onclick = function Die () { document.writeln ( d.roll () ); } </script> I've been going through this great tutorial on how to implement a type-ahead feature on a text field and there's something which hopefully you guys can explain. On the third page there is this function. Code: AutoSuggestControl.prototype.init = function () { var oThis = this; this.textbox.onkeyup = function (oEvent) { if (!oEvent) { oEvent = window.event; } oThis.handleKeyUp(oEvent); }; }; What I don't understand is this line: this.textbox.onkeyup = function (oEvent) { I know about anonymous functions, but I don't know where the value for the parameter oEvent is going to come from. Can someone explain this? Thanks! :) Hi there I am wondering if anyone can tell me the best way to access the functions of an Iframe from the parent of the frame. I have tried Code: var myFrame = document.getElementById('gigmap'); myFrame.flashMouseover(gid); and Code: window.frames['gigmap'].document.flashMouseover(gid); though these didn't work. Basically this is what i want: Mainpage function a(id) receives flash variable 'id' then sends variable 'number' to iframe function b(id) . The part in red is where I have the problem. In case you are wondering what I am doing is sending an id of a gig in my database when its button rolled over in a flash swf to a Google Map (using Google maps javascript API inside the Iframe 'gigmap) and make the corresponding marker on the map jump. I have it so the iframed map markers send to the flash file on rollover though not the other way round...yet! I'm having a javascript problem with nested elements. Consider an example in which you have two nested elements with element 2 being inside of element 1 and only element 1 has an onmouseout event handler. <div style="position:relative;border:1px solid red;width:300px;height:300px" onmouseout="alert('whatever')"> //element 1 <div style="position:absolute;border:1px solid blue;left:50%;top:50%;margin-left:-50px;margin-top:-50px;width:100px;height:100px">//element 2 </div> </div> The 2 problems here are as follows: 1- Moving the mouse pointer over element 2 from element 1 causes a onmouseout with element 1. But this is a minor problem. 2- Moving the mouse pointer from element 2 back to element 1 causes a mouseout with ,I believe, element 2 even though there is no onmouseout event handler here. This is a major problem. Is problem #2 due to possibly an automatic inheritance of the onmouseover handler from element 1 onto element 2 OR is it the result of event capturing or what else? I can't tell either way. If it's due to inheritance how do you stop this from taking place? The strange thing is that tutorials give this kind of scenario with element 2 inside of element 1 with both elements having the same event handler but they don't say what happens in this case with just one element having a specific event handler. Thank you. First class: Code: function ClassOne(){ this.events = []; this.executeEvents = []; this.addEvents = function(event){ this.events.push(event); } this.addExecuteEvents = function(e){ this.executeEvents.push(e) } this.getEvents = function(){ return this.events; } } Second class: Code: function ClassTwo(){ this.add = function(e){ this.addEvents(e) } } ClassTwo.prototype = new ClassOne Here the second class extends the first class, now I want to create two objects of class two, Code: var b = new ClassTwo(); b.add('hello'); var c = new ClassTwo(); c.add('hi'); console.log(c.getEvents()) I just added one event on b and c each, but when I logged the c.getEvents(), it returns both 'hi' and 'hello' events. why?? What am I doing wrong?? how to solve this problem?? Thanks in advance Hi, I would like to know which is the best approach when trying inheritance with js - module pattern. In the example below, I want that parent.hi() be fired from child: Code: var parent = function(){ return{ hi: function(){ console.info('hi'); } } }(); var child = function(){ return{ bye: function(){ console.info('bye'); }, hi: function(){//look he parent.hi(); } } }(); child.hi(); Is there a better way to do this ? Thanks in advance Is it possible to have an input that points to some other function? For example: Code: function someFunction() { alert('It worked.'); } function doAnotherFunction(doIt, otherFunction) { if (doIt == true) { otherFunction(); } } <input type="button" value="test" onClick="doAnotherFunction(true, someFunction());"> Or would I need a switch statement and have all the various functions hardcoded? please bear with my noobishness, but i've been trying for many hours to understand what is going on behind this code: ** Code: function Person() { document.write('constructor: <br/>'+this.constructor); //displays Person constructor this.name = "Rob Roberson"; this.age = 31; } function Employee() { document.write('<br/>constructor: <br/>'+this.constructor); //displays Person constructor this.dept = "HR"; this.manager = "John Johnson"; } Employee.prototype = new Person(); var Ken = new Employee(); document.write('<br/>'+Ken.constructor); //displays Person constructor document.write('<br/>name:'+ Ken.name + '<br/>age:' + Ken.age + '<br/>dept:' + Ken.dept + '<br/>manager:' + Ken.manager ); //displays all properties correctly *** from what i've read, every object references a prototype. in this case, the Employee function will automatically reference a prototype with 'constructor' as its initial value. this command: Employee.prototype = new Person(); will replace the Employee function's prototype to an instance of Person. so now Employee function's prototype will contain both name and age properties, BUT, and this is where i get lost, ITS CONSTRUCTOR PROPERTY GETS REPLACED! so how does: var Ken = new Employee(); actually construct an instance of Employee if the reference to its constructor has been replaced by an instance of Person that only contains name and age properties? how is Ken ever initialized by Employee constructor? |