JavaScript - What's The Difference Between The Object Literal And The New
Similar TutorialsHi, all~..According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example: Code: var x = function (n) {return n+1;}; what is the relationships of x, Object.Prototype and Function.Prototype Thx a lot !!!!!!!!! I keep getting this error and I'm not sure why var flashvars = {'regkey':"<?php $_GET[regkey]?>",'pkey':"<?php $_GET[pkey]?>"}; unterminated string literal [IMG]chrome://firebug/content/blank.gif[/IMG]var flashvars = {'regkey':"<br />\n I need to find a way to check if a field contains sql commands. To begin with, lets just say as an example:select, delete, drop, truncate <script type="text/javascript"> function validate () { var literals= /select/; user_input = document.forms[0].input1.value.search(literals); if (user_input == -1) { alert("test123"); } } </script> <body> <form > <input type="text" size="25" name="input1" value=" "> <input type="button" onClick="validate()" value="check" /> </form> I am new to JS and regular experssions. How do I make it in my regular expression so not only am I searching for /select/ but also for the other sql commands (or anythign for that matter)... essentially multiple literals... eg if it contains /select OR delete OR truncate/ etc. sorry if this is confusing. let me know if i can help in any other way. thanks guys! I have the following code which attaches a function to events in x number of comboboxes (x will probably always = 4, but I do not want to hard-code this). I wish to pass the value of i to the function being attached as well as the value of tempData. In other words, I want the parameters in function to be the value, not a reference variable. In the current example, I am using the hard-coded variable ci. This I want to be replaced by a literal created when the event handler is attached (the value of the loop variable i). Also, notice that I get the filter value in the event handler (assigned to the variable ct). I would like to replace this code with the value of tempData which would also be determined when the evenet is attached (it is the same value in this case, but it keeps the onChange event from having to do this each time it runs). Code: var props = { col_0: "select", col_1: "select", col_2: "select", col_3: "select", btn_reset:true, display_all_text: "-Show All-", on_filters_loaded: function(o){ //reset all filters var slcIndexes = o.GetFiltersByType(o.fltTypeSlc, true); //o.fltTypeSlc = 'select' for(var i=0; i<slcIndexes.length; i++){ //this public method returns a filter DOM element by column index var slcElm = o.GetFilterElement(slcIndexes[i]); //tempData = slcElm.options[slcElm.selectedIndex].text; //window.alert(tempData + " " + slcElm); tf_AddEvent(slcElm, 'change', onchangeFn=function(){ //ci is the column index for the column to filter on. ct is the new text from the combobox to filter on var ci; ci = 2; var ct = tf_outputTable.GetFilterValue(ci); tf_outputTable.ClearFilters(); //window.alert("ci= " + ci + " ct= " + ct); tf_outputTable.SetFilterValue(ci, ct); tf_outputTable.Filter(); }); //end tf_AddEvent } } } setFilterGrid("outputTable",props); Hi guys , i am getting this error " unterminated string literal" but iam unable to locate the problem..iam using fire bug for firefox.. any idea from where this error comes ? thanks So I can't figure out why I keep getting the error.... Code: unterminated string literal document.write("<input type=\"button\ value=\"" + phrases [i][j] + "\" Code: <form name="pirateForm"> <div align="center"> <script type="text/javascript"> phrases = [["Greetings","hello","pardon me","excuse me","hows it going"], ["People","sir","madam","woman","children"], ["Questions","where is","can you help me find","is that","how far is it to?"], ["Ariticles","the","my","your","there"], ["Adjectives","outstanding","attractive","happy","dead"], ["places","restroom","restaurant","hotel","pub"], ["Desires","I would like to","I desire","I wish I knew how to","my mother told me to"], ["Actions","have a great dinner","have a cocktail","fall on the ground","get drunk"]]; for(var i = 0; i < phrases.length; i++) { var category = phrases[i][0]; document.write("<tr valign='top'><td>" + category + ": <td>"); for(var j = 1; j < phrases [i].length; j+=2) { document.write("<input type=\"button\ value=\"" + phrases [i][j] + "\" onClick='document.pirateForm.Output.value += \"" + phrases [i][j+1] + "\";'>\n"); } } </script> </div> <div align="center"> <textarea id="task_list" rows="5" cols="130"></textarea> <input type="button" value="Clear" onClick="this.form.reset()" /> </div> </div> </form> Hello, I have the following code: A = { "value" : "a", }; B = A ; B.value = "b"; alert (A.value); // => b I expected A.value to be "a". Can someone explain what I'm thinking wrong? And: how can I change values of a new object, without changing the parent-object ? tnx Hello, I created a simple WYSIWYG for creating CSS based webpages. It works exactly as assumed in Safari and Chrome. However, in firefox, when you copy/paste more than one line of text, instead of formatting it as html, in puts in line breaks causing the array storing all of the data to break into multiple lines and causing an unterminated string literal. Can anyone, 1. suggest why it is behaving this way? 2. suggest a work around to allow it to work on FF? im sure its the scripting, im new to js, can anyone Tell me why im getting these 2 error messages? thank you!!!!!!! detailed error: unterminated string literal Error: onPageUnload is not defined function writeMovie1() {detectBrowser();if(windowsInternetExplorer) {document.write('<object id="id3" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="150" height="16" style="height: 0px; left: 160px; position: absolute; top: 150px; width: 150px; z-index: 1; "><param name="src" value="musicfiles/VenusStereo.m4a" /><param name="controller" value="false" /><param name="autoplay" value="true" /><param name="scale" value="tofit" /><param name="volume" value="100" /><param name="loop" value="true" /></object>');} else if(isiPhone) {document.write('<object id="id3" type="video/quicktime" width="150" height="16" style="height: 0px; left: 160px; position: absolute; top: 150px; width: 150px; z-index: 1; "><param name="src" value="musicfiles/VenusStereo.m4a"/><param name="controller" value="false"/><param name="scale" value="tofit"/></object>');} else {document.write('<object id="id3" type="video/quicktime" width="150" height="16" data="musicfiles/VenusStereo.m4a" style="height: 0px; left: 160px; position: absolute; top: 150px; width: 150px; z-index: 1; "><param name="src" value="musicfiles/VenusStereo.m4a"/><param name="controller" value="false"/><param name="autoplay" value="true"/><param name="scale" value="tofit"/><param name="volume" value="100"/><param name="loop" value="true"/></object>');} setTransparentGifURL('Media/transparent.gif');function applyEffects() {var registry=IWCreateEffectRegistry();registry.registerEffects({stroke_0:new IWStrokeParts([{rect:new IWRect(-5,5,10,467),url:'Welcome_files/stroke.png'},{rect:new IWRect(-5,-5,10,10),url:'Welcome_files/stroke_1.png'},{rect:new IWRect(5,-5,705,10),url:'Welcome_files/stroke_2.png'},{rect:new IWRect(710,-5,11,10),url:'Welcome_files/stroke_3.png'},{rect:new IWRect(710,5,11,467),url:'Welcome_files/stroke_4.png'},{rect:new IWRect(710,472,11,10),url:'Welcome_files/stroke_5.png'},{rect:new IWRect(5,472,705,10),url:'Welcome_files/stroke_6.png'},{rect:new IWRect(-5,472,10,10),url:'Welcome_files/stroke_7.png'}],new IWSize(716,477))});registry.applyEffects();} function hostedOnDM() {return true;} function onPageLoad() {loadMozillaCSS('Welcome_files/WelcomeMoz.css') adjustLineHeightIfTooBig('id1');adjustFontSizeIfTooBig('id1');adjustLineHeightIfTooBig('id2');adjust FontSizeIfTooBig('id2');Widget.onload();fixupAllIEPNGBGs();fixAllIEPNGs('Media/transparent.gif');applyEffects()} function onPageUnload() {Widget.onunload();} ok so Code: <p> Howdy <p> expressed as a literal string that is passed to the setTimeout() function might look like this: Code: setTimeout("document.getElementById('first').innerHTML = '<p>' + 'HOWDY' + '<\/p>';", 2000); ..so I guess you can't just put quotes around an expression like this: "'<p> HOWDY <\/p>;" So tags have to be isolated, but it get confusing with expressions like this, which I am not sure how to express as a string: Code: <p><h2 class="pos_left"> <img src="car1.jpg" name="slide" width="400" height="250" /> </h2> </p> ^ I wish I could change the " in there to ' and then just wrap the whole thing in double " This is what I came up with but it did not work: Code: setTimeout("document.getElementById('first').innerHTML = '<p>' + '<h2' + 'class='pos_left'' + '>' + '<img' + 'src='car1.jpg'' + 'name='slide'' + 'width='400'' + 'height='250'' + '/>' + '</h2>' + '<\/p>';", 4000); Hi.. I am facing identifier starts immediately after numeric literal error in firefox onclick="document.location.href='<%= themeDisplay.getPathMain() %>/portal/ext/asite/assignOrg'"/> can any 1 solve this?? Hi, every time I try and alert: [ { number:0, secondnumber:0 }, { number:2, secondnumber:1 }, { number:1, secondnumber:2 } ] it just shows [object object], [object object], [object object]. Why is this and what can I do to make the record be shown as it is above in an alert? Thanks. I can't get any info from Firebug except that one line, uncaught exception [object Object]. The code fully worked, then I needed to make it dynamically create Sortables from the scriptaculous library based on how many X were in a table in my database, which I've done, and I'm thinking it may be a simple slight parse error of some type, I'm not too good with Javascript, because now my script barely works. I've double checked the script's source code, the PHP variables are exactly what they should be. Code: print<<<HERE Sortable.create('sortlist$box', { tag: 'img', overlap:'horizontal',constraint:false, containment: $list, dropOnEmpty: true, onChange: function(item) { var list = Sortable.options(item).element; if(changeEffect) changeEffect.cancel(); changeEffect = new Effect.Highlight('changeNotification', {restoreColor:"transparent" }); }, onDrop: function(item) { var thing=Sortable.options(item).element.identify(); var anchors = document.getElementById(thing).childNodes.length-2; if(anchors > 20){ alert('This box had 20 creatures in it already, your last action has not been saved.'); window.location.reload(); } else{ new Ajax.Request("saveImageOrder.php", { method: "post", parameters: { data: Sortable.serialize("sortlist$box") } }); } } }); HERE; $box++; } ?> }); </script> if you solve this I'll send ya $10 via paypal I created a method for displaying an object's properties: Code: renderfunction = false; function showProperty (object, property) { document.write ('<td class="type">' + (typeof object[property]) + '</td>' + '<td class="name">' + property + '</td>'); document.writeln('<td class="value">' + ( (typeof object[property] != 'function') ? object[property] :( (property != 'showProperties') ? ( renderfunction ? object[property]() : ('<span class="self">NOT RENDERED</span>') ) : ('<span class="self">THIS</span>') ) ) + '</td>'); document.writeln('<td class="hasOwnProperty" >' + ( object.hasOwnProperty(property) ? "Local" : "Inherited" ) + '</td>'); if (typeof object[property] == 'function') { document.writeln ('<td class="function">' + object[property] + '</td>'); } else { document.writeln ('<td class="function"> </td>'); } } As long as renderfunction = false, the object is fine coming out of this function. However, if I change renderfunction to true, all my properties become undefined. Why isn't this working as I expect it to? How should I fix it? Thanks in advance, -Brian. I'm writing a program that involves a network of interconnected nodes (or simply objects in my example below). It depends on being able to access properties of an object's linked objects (a bit oddly worded, sorry)... Problem is I'm not sure how to properly access those properties... see below please. <script> //This is an example of a problem im having in my own code... //I want to access the name of the object within the links array wintin the object... var objA = {name: "Object A", links: [objB, objC]}; var objB = {name: "Object B", links: [objC, objD, objE]}; var objC = {name: "Object C", links: [objB]}; var objD = {name: "Object D", links: [objE]}; var objE = {name: "Object E", links: [objD]}; //ex: I want to access the name of Object A's first link... console.log(objA.links[0].name); </script> I'm hoping to get "Object B"... But instead I get: TypeError: Result of expression 'objA.links[0]' [undefined] is not an object. Is there another way around this? Any thoughts are appreciated. Hello together! I generate html code with jsp. In that jsp there a several framesets and frames. And yes i know, frames are not really up to date but it's an old program and i have to deal with it now. Anyway, in the top frameset i have an onload attribute like onload="load()". In the function load i want to access the Element.prototype object. But unfortunately typeof Element gives me "undefined". So i looked a little deeper and found that window.toString() gives me "[object]" and not as expected "[object window]" so somehow my window doesn't know that its construcor is Window. window.construcor is "undefined" as well. And i don't have access to the Element object. I really don't know where the error could be. When the page is loaded and i access the same window over the console, then everything is right. But in my function a can't get access to the objects i need. I also don't know what part of the code could be useful to post here, but maybe someone had a similar problem before? i should say that this problem only occurs in IE8. In IE9 it works perfectly. Has anyone any idea?? Hi all, I'm stumped on finding a way in javascript to create an object factory whose instances are also object factories. In short I want something like that below, but no joy ... any clues? Code: function createClass () { return new createClass() function createClass() { return new createInstance () function createInstance () { //Default properties, values and methods which might later be extended } } } var createDoor = createClass(); var door1 = createDoor(); var door2 = createDoor(); var createChair = createClass(); var chair1 = createChair (); var chair2 = createChair (); Ignore post (if mod, please delete)
Hello. Is there any way to get the variable name of an object from inside the object? E.g. PHP Code: function Bla(){ this.write = function(){ document.write(<objectname>); } } obj1 = new Bla(); obj1.write(); //Outputs obj1 Here is my script: PHP Code: function myTimer(seconds, obj){ this.seconds = seconds; this.obj = obj; this.startTimer = function(){ if(this.seconds>0){ this.seconds--; this.obj.innerHTML = this.seconds; this.timer = setTimeout("Timer.start()",1000); } } } Timer = new Timer(10, obj); Timer.startTimer(); Now the problem is that the variable that contains the object must be named "Timer". This way I cannot create new timer objects with different variable names I have tried: this.timer = setTimeout("this.start()",1000); but it doesn't work. That's why it would be good to detect the variable name and instead use something like this: this.timer = setTimeout(varname+".start()",1000); I would rather not have to pass the variable name through a parameter like this: Timer1 = new Timer(10, obj, "Timer1"); Thanks in advance. Quote: menu: function( a, b ) { $( b ).observe( 'click', function( event ) { event.stop(); if( $( a ).visible() ) { $( a ).hide(); $( b ).removeClassName( 'selected' ); document.stopObserving( 'click' ); } else { $( a ).show(); $( b ).addClassName( 'selected' ); document.observe( 'click', function( e ) { if( e.target.id != a && e.target.id != b && !Element.descendantOf( e.target, $( a ) ) ) { $( a ).hide(); $( b ).removeClassName( 'selected' ); document.stopObserving( 'click' ); } }); } }); $$( '#' + b + ' > a' ).each( function( element ) { element.observe( 'click', function( event ) { $( a ).hide(); $( b ).removeClassName( 'selected' ); document.stopObserving( 'click' ); }); }); } This work's perfrect accept when i use it with others on the menu it leaves the other ones open, how do i get it to close the open one when i open a new menu.. Thanks. |