lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I tried putting the following JavaScript code into the Closure Compiler web interface in advanced optimization mode : It generated the following compiled code : But when I put the compiled code back into the Closure Compiler , it managed to produce an even shorter version : Does this mean I should be running the Closur... | function f ( some_object ) { if ( some_object.foo == 1 ) { console.log ( some_object.bar ) ; } else { alert ( some_object.bar ) ; } } var my_object = { foo : 1 , bar : 2 } ; f ( my_object ) ; var a = { b:1 , a:2 } ; 1 == a.b ? console.log ( a.a ) : alert ( a.a ) ; console.log ( 2 ) ; | Should I run the Google Closure Compiler multiple times to optimize my code more ? |
JS | I make an intentional error using a character that seems nonstandard but is availiable to use : Apparently ᛨ character is a version of è character ( a utf-8 normal text character a , b , c is text ) vs ( non text ☎ , ® , ෴ , % ) è === http : //unicode-table.com/en/00E8/ᛨ === http : //unicode-table.com/en/16E8/I do n't ... | var ᛨ= { } ; ᛨ.causeError ( ) Uncaught TypeError : è.causeError is not a function Encoding hex dec ( bytes ) dec binaryUTF-8 C3 A8 195 168 50088 11000011 10101000UTF-16BE 00 E8 0 232 232 00000000 11101000UTF-16LE E8 00 232 0 59392 11101000 00000000UTF-32BE 00 00 00 E8 0 0 0 232 232 00000000 00000000 00000000 11101000UT... | Apparently Some non standard Characters are seen as regular Characters |
JS | The only difference I see is that using the first one you must call with new to let the language know its constructing a new object , is it essentially just constructing an object where 'this ' refers to the new object being created ? ? i.e same as doing this.where as the second returns an object so you can just writei... | function Person ( age , name ) { this.name = name ; this.age = age ; this.speak = function ( ) { ... } } function Person ( age , name ) { var p = { } p.name = name ; p.age = age ; p.speak = function ( ) { ... } return p ; } { age : 12 , name : `` mark '' , speak : function ( ) { ... } } Person ( 12 , '' mark '' ) new P... | Two ways of constructing an object in Javascript |
JS | I am using CI and windows 7.From my view file I am calling a function in ajax which is in controller.In my ajax I am passing a string as Pack & Send , but when I echo same string in controller function it is just echoing Pack.My ajax call looks likeOn alert i get entire string i.e . Pack & Send.Now my php function in c... | < script > $ ( document ) .ready ( function ( ) { $ ( `` select # items '' ) .change ( function ( ) { var country_id = $ ( `` select # items option : selected '' ) .attr ( 'value ' ) ; $ ( `` # state '' ) .html ( `` '' ) ; $ ( `` # city '' ) .html ( `` '' ) ; if ( country_id.length > 0 ) { $ .ajax ( { type : `` POST ''... | PHP function does not display string after `` & '' |
JS | I have plenty of confusion in regular expression and I am trying to solve them . Here I have the following string : My two different regexes , where I only changed the position of the dot : Why does the first regex eats the last `` e '' ? And also how does this negative lookahead make this * quantifier non greedy ? I m... | { start } do or die { end } extended string ( . ( ? ! { end } ) ) * //returns : { start } do or di //^ See here ( ( ? ! { end } ) . ) * //returns : { start } do or die //^ See here | difference in match due to the position of negative lookahead ? |
JS | I am working on an exercise where I prompt the user for a list of names , store the list of names in an array , sort the array in ascending order , and print the list of names ( one per line ) . When I do so , I see a numeric value displayed instead of one name per line . Why is this happening ? | var namesArray = [ ] ; do { var names = prompt ( `` Enter a name : `` ) ; namesArray.push ( names ) ; } while ( names ! = `` '' ) namesArray.sort ( ) ; for ( var name in namesArray ) { document.write ( name ) ; } | JavaScript returning numeric value instead of string ( s ) after sorting array |
JS | I have a function that I 'm using to filter elements on a page . It will check the data attribute of the clicked element against class names on the filtered objects ( .filter-boy ) .Since the features are broken up into Categories and Subcategories , I want to hide any .subcategory parent containers that are empty . So... | $ ( `` .feature-dropdown li '' ) .click ( function ( ) { var value = $ ( this ) .attr ( 'data-filter ' ) ; if ( value === `` all '' ) { $ ( '.filter-boy ' ) .show ( '1000 ' ) ; $ ( '.category_header ' ) .show ( '1000 ' ) ; $ ( 'header.persona ' ) .addClass ( 'hidden ' ) ; } else { $ ( 'header.persona ' ) .not ( ' . ' +... | Click function requires an extra click to fully execute . It should all happen in one click |
JS | I have the following code which works fine for the first row , but does n't seem to loop through the tableMy understanding ( which is very basic ) is that the code will look for a id called prodref and then copy the cell value to the text box , and work its way down until it has completed all rows . | < ! doctype html > < html > < head > < meta charset= '' utf-8 '' > < title > Untitled Document < /title > < /head > < body > < table width= '' 100 % '' border= '' 0 '' cellspacing= '' 2 '' cellpadding= '' 2 '' id= '' demotbl '' > < tr > < th scope= '' col '' > Header 1 < /th > < th scope= '' col '' > Header 2 < /th > <... | Why is my javascript not looping |
JS | Here is a quotation from MDN about 'for ' statement : An expression ( including assignment expressions ) or variable declaration . Typically used to initialize a counter variable . This expression may optionally declare new variables with the var keyword . These variables are not local to the loop , i.e . they are in t... | for ( var i = 0 ; i < 10 ; i++ ) { for ( var j = 0 ; j < 10 ; j++ ) { // ... } } for ( var i = 0 , j = 0 ; i < 10 ; i++ ) { for ( j = 0 ; j < 10 ; j++ ) { // ... } } | Optimization - For statement and variable declarations |
JS | So , there is one thing I ca n't get my head around.I have no problem understanding that : givesWhat I really do n't get though is why gives '' [ object Object ] [ object Object ] '' and not `` 0 [ object Object ] '' My understanding is that the first { } is a block statement and thus is ignored . We then do have + [ ]... | { } + [ ] + { } + [ 1 ] `` 0 [ object Object ] 1 '' { } + [ ] + { } | Object coercion in js starting with block statement |
JS | I have defination of object like : I tried to initializae this like corresponding interface : It does not work ... Can I use this suffix ? I tried this : I create instance like this : | let translateObj : ITranslate ; let obj = new translateObj = { keyTranslate : 'subjectId ' , outName : 'name ' } export class MapperServiceArray < T > implements IMapperServiceArray < T > { public constructor ( public key : string | number , public translate ? : ITranslate ) { } let mapperArray = new MapperServiceArray... | How to fill object JS inside new ? |
JS | My issue is that JavaScript is reporting wrong width and height for one particular mp4 file.This is the code I 'm using to find out video width and height ( simplified ) : I am not sure if something is wrong with metadata of the file , but it gets more interesting : UNIX systems recognize width and height CORRECTLY ( 6... | // loadedmetadata event of video elementonLoadedMetadata ( event ) { videoWidth = event.srcElement.videoWidth ; videoHeight = event.srcElement.videoHeight ; } | JS detects wrong width and height for one particular .mp4 file |
JS | I 'm creating a module that extends existing application . I 've received a variable device and I want to create myDevice that will always hold the same data . Lets say that data is contained in an array : https : //jsfiddle.net/hmkg9q60/2/What I would like to obtain is to be sure , that myDevice will always hold the s... | var device = { name : `` one '' , data : [ 1 , 2 , 3 ] } ; var myDevice = { name : `` two '' , data : [ ] } ; myDevice.data = device.data ; // Assign array referencedevice.data.push ( 4 ) ; // Push works on array referenceconsole.log ( device.data ) ; // [ 1 , 2 , 3 , 4 ] console.log ( myDevice.data ) ; // [ 1 , 2 , 3 ... | JavaScript reference drop |
JS | My zingchart 's last element 's color does not match with legend , and keeps on changing unlike the others . Any Ideas ? Everything else works good . Though I 'm parsing this data through MySQL database , this is how the JavaScript looks like.My code : | < script > var myData = [ `` 12 '' , '' 15 '' , '' 7 '' , '' 20 '' , '' 2 '' , '' 22 '' , '' 10 '' , '' 7 '' , '' 7 '' , '' 10 '' , '' 8 '' , '' 15 '' , '' 9 '' ] ; var myData = myData.map ( parseFloat ) ; var myLabels = [ `` General Verbal Insults '' , '' General Beatings\/Pushing '' , '' Terrorizing\/Threatening Rema... | Zingchart last element keeps changing color and not matching with legend |
JS | Please forgive my English . I am not a native speaker.My problem comes when I write code like thisThe problem is that 0 is supposed to be a valid value , but it will be overlook because 0 is falsy in Javascript and it will set to the default value on the right of ||.Is there a way to do a fix so 0 is n't treated as fal... | luminosity = settings.luminosity || 50 ; opacity = settings.opacity || 100 ; luminosity = `` luminosity '' in settings ? settings.luminosity : 50 ; | How do I write an || expression in Javascript where 0 is n't treated as a falsy value ? |
JS | I like to think I understand JavaScript , but I found something unexpected today and I was hoping someone could explain to me why it happens.Take this codeThe output is not what I was expecting . Calling animalData.getCow ( ) results in `` cow '' just as you would expect . But it 's what gets return by the second conso... | var animalData = { cow : '' cow '' , sheep : '' sheep '' , getCow : function ( ) { return this.cow ; } , animalList : [ { animalId : this.cow , label : '' This is a cow '' } , { animalId : this.sheep , label : '' This is a sheep '' } ] } ; console.log ( animalData.getCow ( ) ) ; console.log ( JSON.stringify ( animalDat... | Using 'this ' keyword in JavaScript object |
JS | This was presented yesterday at TC39 . You can find the gist here : Could someone please explain to me how this thing works ? For the record it 's only working in non-strict mode.Thank you . | var p = ( ) = > console.log ( f ) ; { p ( ) ; // undefined console.log ( f ) ; // function f ( ) { } f = 1 ; p ( ) ; // undefined console.log ( f ) ; // 1 function f ( ) { } p ( ) ; // 1 console.log ( f ) ; // 1 f = 2 ; p ( ) ; // 1 console.log ( f ) ; // 2 } | Scoping and closure oddities in javascript |
JS | I am writing a mobile application using Phonegap/Cordova.The mobile application needs information from a server-side application , which I have written . I created an API to get this information.One of the first things the API does is verify the mobile application is an application which I have written.It does this usi... | var SIGNATURE = SHA512 ( MY_APP + MY_PUBLIC_API_KEY + TIMESTAMP + NONCE + MY_SECRET_API_KEY ) ; var auth = `` path=MY_APP , key=MY_PUBLIC_API_KEY , time=TIMESTAMP , nonce=NONCE , signature=SIGNATURE '' $ .ajax ( { type = `` POST '' , url : url , headers : { `` Authorization '' : auth } } ) ; // there is some regex to `... | Securing API Secrets On Clients Using Custom API |
JS | I made a new windowand I want to reach its body withand from there use methods like .find ( ) , .html ( ) This works good on FF & Chrome but not IE . Found also a related post to this one.How to fix this in IE ? ie , how to make this work cross browser ? jsFiddle - notice that the close button never shows up in IE . | var win = window.open ( `` '' , `` '' , `` width=400 , height=200 '' ) ; var $ windowBody = $ ( win.document.body ) ; | reach content of new window.open |
JS | I 'm trying to achieve following in vanila javascriptAt the moment I 'm at this stageBut I need to specifically check if there is an anchor tag < a > with class .item after # myDiv , as there can and can not be one , and I need to apply specific styling to # myDiv in each case . | $ ( ' # myElement ' ) .next ( ' a ' ) .length > 0 document.getElementById ( 'myElement ' ) .nextSibling.length > 0 | Replicating jQuery 's .next ( ' a ' ) with vanila javascript |
JS | I recently read the react.js documentation and found inconsistencies in setting the state based on previous state value . Here is that chunk of code : I thought this way ( ) = > this.setState ( { count : this.state.count + 1 } ) of setting state is wrong and you should use callback for that purpose instead . So I 've r... | class Example extends React.Component { constructor ( props ) { super ( props ) ; this.state = { count : 0 } ; } render ( ) { return ( < div > < p > You clicked { this.state.count } times < /p > < button onClick= { ( ) = > this.setState ( { count : this.state.count + 1 } ) } > Click me < /button > < /div > ) ; } } | Set state based on previous one in render function |
JS | Consider following JavaScript code ( tested in Firefox ) : Both alerts are shown , suggesting that both statements are true.Could you provide a reasonable explanation ? | function f ( a ) { if ( a == undefined ) { alert ( 'undefined ' ) ; } if ( a == null ) { alert ( 'null ' ) ; } } f ( ) ; | Quantum duality : variable is null and undefined at the same time ? |
JS | I have the following array objectsI would like to know how to convert it to the following JavaScript object . | var stats = [ [ 0 , 200,400 ] , [ 100 , 300,900 ] , [ 220 , 400,1000 ] , [ 300 , 500,1500 ] , [ 400 , 800,1700 ] , [ 600 , 1200,1800 ] , [ 800 , 1600,3000 ] ] ; var stats = [ { x:0 , y:200 , k:400 } , { x:100 , y:300 , k:900 } , { x:220 , y:400 , k:1000 } , { x:300 , y:500 , k:1500 } , { x:400 , y:800 , k:1700 } , { x:... | Convert Array of Object to Regular JavaScript Object |
JS | I 'm guessing this is some known issue I 've just somehow never come across . I have a multi-dimensional array being sent over AJAX to PHP as follows : Here 's what PHP receives , according to print_r ( $ _POST [ 'vids ' ] ) : All good . Three different videos.Now for the weirdness.For some reason , this outputs : One ... | let pd = { vids : $ .map ( yt_vids_preview.find ( 'tr : has ( td : checked ) ' ) , function ( el ) { let vid = $ ( el ) .data ( 'vid ' ) ; return { vid_id : vid.contentDetails.videoId } ; } ) } ; $ .ajax ( { data : pd , url : 'foo.php ' , type : 'post ' } ) Array ( [ 0 ] = > Array ( [ vid_id ] = > kCkrVN7IVbo ) [ 1 ] =... | PHP foreach weirdness with multi-dim array sent over AJAX |
JS | I have this code ( JSFiddle ) This is an abstraction of a real problem I 'm having.So - I would expect the call to OBJ.thePrivateVarTimeout ( ) to wait 10 and then alert with 23 ( which I want it to access through the other exposed method ) .However self does n't seem to be setting correctly . When I am setting self = ... | var OBJ = function ( ) { var privateVar = 23 ; var self = this ; return { thePrivateVar : function ( ) { return privateVar ; } , thePrivateVarTimeout : function ( ) { setTimeout ( function ( ) { alert ( self.thePrivateVar ( ) ) ; } , 10 ) ; } } } ( ) ; alert ( OBJ.thePrivateVar ( ) ) ; OBJ.thePrivateVarTimeout ( ) ; | How can I scope this `` public '' method correctly ? |
JS | I was trying to understand OOP model of JavaScript , so I was reading this article : https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScriptThe following code was interesting : What was interesting and not clear to me is this line : I did n't understand so I tested the code ... | function Person ( gender ) { this.gender = gender ; alert ( 'Person instantiated ' ) ; } Person.prototype.gender = `` ; var person1 = new Person ( 'Male ' ) ; var person2 = new Person ( 'Female ' ) ; //display the person1 genderalert ( 'person1 is a ' + person1.gender ) ; // person1 is a Male Person.prototype.gender = ... | Why set a property both on the function and its prototype ? |
JS | I 'm trying to make a _.combinations function ( underscore mixin ) that takes three parameters arr , pockets , duplicates . Here 's a test that I designed to show how the behavior should be.I was wondering before I go and create this function if it existed within a library already . Perhaps this specific function alrea... | expect ( _.combinations ( [ 1 , 2 ] , 1 , false ) ) .to.be.equal ( [ [ 1 ] , [ 2 ] ] ) expect ( _.combinations ( [ 1 , 2 ] , 1 , true ) ) .to.be.equal ( [ [ 1 ] , [ 2 ] ] ) expect ( _.combinations ( [ 1 , 2 , 3 ] , 2 , false ) ) .to.be.equal ( [ [ 1,2 ] , [ 1,3 ] , [ 2,3 ] ] ) expect ( _.combinations ( [ 1 , 2 , 3 ] , ... | Function that returns array of array combinations |
JS | Giving the following string ... ... how to split it into an array using the 2 delimiters ( `` _ '' , `` { and } '' ) but also keeping the delimiters in each element of the array ? The goal is : My best bet was : as you see , it fails to reproduce the desirable array . | `` Here is my very _special string_ with { different } types of _delimiters_ that might even { repeat a few times } . '' [ `` Here is my very `` , `` _special string_ '' , `` with `` , `` { different } '' , `` types of `` , `` _delimiters_ '' , `` that might even `` , `` { repeat a few times } '' , `` . '' ] let myText... | Split string in between 2 delimiters and include them |
JS | It may not be common knowledge , but `` Javascript on many ( all ? ) modern browsers seems to create variables on the window object for DOM elements with IDs '' .Knowing this I 'd like to be able to delete these variables and below is some code I 've tried without success . Also consider my screenshot of console.log st... | < ! DOCTYPE html > < html > < head > < script > setTimeout ( function ( ) { //poor man 's document/ready var allElements = document.getElementsByTagName ( `` * '' ) , elementId ; for ( var i=allElements.length ; i -- ; ) { elementId = allElements [ i ] .id ; if ( elementId & & window [ elementId ] instanceof HTMLElemen... | Why is n't it possible to delete Javascript variables automatically generated from the DOM ? |
JS | I have a structure like this : jQueryLike my code say , I wan na get the $ x/ $ y variable of array . ( with .val ( ) ; function I get the string inside textbox ) Is there a way ? Thank you ! | < input type='text ' name='value [ $ x ] ' class='kp ' > < input type='text ' name='value [ $ y ] ' class='kp ' > $ ( `` .kp '' ) .keyup ( function ( ) { $ ( 'input [ name^= '' value '' ] ' ) .each ( function ( ) { ***** HERE I WANT TO PRINT THE $ x/ $ y VALUE INSIDE [ ] ***** } ) ; } ) ; | jQuery PHP Handle input array |
JS | I 'm more of a back-end guy than a front-end guy , but JavaScript intrigues me . I 'm trying to wrap my head around what seem to me to be multiple different methods of modeling objects.For the past few years I 've been primarily been writing code that looks similar to this ( assume jQuery is loaded ) : This way I can s... | var TicketForm = { elements : [ 'input ' , 'textarea ' , 'select ' , 'checkbox ' ] , enable : function ( form ) { this.elements.forEach ( function ( el ) { form.find ( el ) .prop ( 'disabled ' , false ) ; } ) ; } , disable : function ( form ) { this.element.forEach ( function ( el ) { form.find ( el ) .prop ( 'disabled... | What are the proper applications of these different methods of object creation in JavaScript |
JS | I have been programming Javascript for a little while now , and still am not quite sure if I am being too lazy or not.I have a lot of : However , sometimes it just becomes too verbose . For example , now I am doing : That 's because in the following lines I am treating redirectURLs as an object , although it might not ... | if ( typeof ( something ) === 'undefined ' ) { // .. } var redirectURLs = hotplate.get ( 'hotCoreAuth/redirectURLs/success ' ) || { } ; var redirectURLs = hotplate.get ( 'hotCoreAuth/redirectURLs/success ' ) ; if ( typeof ( redirectURLs ) === 'undefined ' ) { redirectURLs = { } } | How to make sure a variable is an object |
JS | I do n't understand why , but this code gives me a JavaScript error : Error Exception thrown : invalid quantifierWhat 's wrong with it ? | < script type= '' text/javascript '' > String.prototype.format = function ( values ) { var result = this ; for ( var i = 0 , len = values.length ; i < len ; i++ ) { result = result.replace ( new RegExp ( `` { `` + i + `` } '' , `` g '' ) , values [ i ] ) ; } return result ; } ; alert ( `` Hi { 0 } , I 'm { 1 } . Are yo... | Why does my JavaScript regex not work ? |
JS | what is the better solution:1 ) make one CSS-File with all Media-Querys for all supported resolutions2 ) make a CSS-File for every supported resolution and load them in the header ? ? ? I mean , in attempt 2 ) there are more requests , but is that really that important ? | < link rel= '' stylesheet '' href= '' mobile.css '' type= '' text/css '' media= '' all '' / > < link rel= '' stylesheet '' href= '' mobile.css '' type= '' text/css '' media= '' screen and ( min-width:240px ) and ( max-width:639px ) '' / > < link rel= '' stylesheet '' href= '' tablet.css '' type= '' text/css '' media= '... | CSS - all media-querys in one file ? or load separated CSS-files ? |
JS | The current example uses a pseudo class to draw a line with small elements for main titles and sub titles . Every element which has a class line will require a line on the left hand side . Problem : i am having to increase the height to 200 % to make it work . When the content is increased , that line extends further t... | p { margin : 0 ; padding : 0 ; } .view-timeline-block { padding : 0 5em ; line-height : 28px ; } .view-timeline-block .ml-container { padding-left : 25px ; } .view-timeline-block .line { position : relative ; } .view-timeline-block .line : after { background : black none repeat scroll 0 0 ; content : `` '' ; height : 2... | Spacing gaps in Vertical border left |
JS | I am trying to solve a code challenge for a job app , but I am stuck and would appreciate any help.Question : Create a class Foo that has a method called refCount . Calling refCount on the class or any of its instances should return how many total instances exists . Example : I have something like this so far : I also ... | var f1 = new Foo ( ) ; f1.refCount ( ) ; // should be 1Foo.refCount ( ) ; // should be 1var f2 = new Foo ( ) ; f1.refCount ( ) ; //should be 2f2.refCount ( ) ; // should be 2Foo.refCount ( ) ; // should be 2 function Foo ( ) { this.refCount = function ( ) { ++Foo.prototype.refs ; return Foo.prototype.refs ; } } Foo.pro... | Code Challenge : Create a class Foo that tracks the number of total object instances |
JS | I have the following object , with points per sport for an individual person . This information comes out of a database , based on the search for `` Jack Miller '' I would like to display the top 2 ( 3 ) sports for the name on my HTML page . Do to that , I was thinking to extract the information into an array like this... | Jdata = { `` name '' : `` Jack Miller '' , `` sports '' : { `` Basketball '' : 2 , `` Football '' : 3 , `` Iceskating '' : 5 , `` Running '' : 4 , } } SportVal = [ ] ; SportNames = [ ] ; for ( var key in this.Jdata.sports ) { if ( ! this.Jdata.sports.hasOwnProperty ( key ) ) { continue ; } this.SportVal.push ( this.Jda... | Filter highest numbers out of an object |
JS | So I have two unordered lists , with the same amount of items in them . So let 's assume items in unordered list # 2 are all hidden . The only way to make them appear is if you click on the items in unordered list # 1.so basicallyNow the way I 'm trying to accomplish this is using the index ( ) method , but I 'm not su... | < ul class= '' list1 '' > < li > item 1 < /li > < li > item 2 < /li > < li > item 3 < /li > < li > item 4 < /li > < /ul > < ul class= '' list2 '' > < li class= '' hide '' > item 1 < /li > < li class= '' hide '' > item 2 < /li > < li class= '' hide '' > item 3 < /li > < li class= '' hide '' > item 4 < /li > < /ul > $ ( ... | jQuery targeting elements with index ( ) |
JS | Currently as I 'm displaying different elements with jQuery , I 'm re-creating them from scratch and adding them to the page.I 've come to a point where I want the user to be able to check a box on one element , then click a button to see some different information , then be able to switch back and see the earlier box ... | $ ( `` # table '' ) .on ( `` click '' , `` .on '' , function ( ) { $ ( this ) .removeClass ( `` on '' ) ; $ ( this ) .addClass ( `` off '' ) ; } ) ; $ ( `` # table '' ) .on ( `` click '' , `` .off '' , function ( ) { $ ( this ) .addClass ( `` on '' ) ; $ ( this ) .removeClass ( `` off '' ) ; } ) ; | Re-create information elements for a different object or hide them ? |
JS | Probably a duplicate question but can not find the answer.element.style.display is not what rendered in the browser . Instead of returning the actual value ( ie . block or inline etc ) , it returns empty . Tested in Chrome 56.0.2924.87 ( 64-bit ) .How do I get the actual rendered value ? | function displayStyle ( aEvent ) { aEvent.target.textContent=aEvent.target.style.display ; } window.onload = function ( ) { var top_array = document.getElementsByClassName ( `` top '' ) ; for ( var i = 0 ; i < top_array.length ; i++ ) { top_array [ i ] .addEventListener ( `` click '' , displayStyle , false ) ; } } .top... | element.style.display is not what rendered in the browser |
JS | What would be the proper or the best way to collect all data from DB with promises , but with using native Node promises.The goal is only to present what is selected : Possible solutions : Track index for each data selected ( eg . index of C will be 1 ) Object MapAdd else { allPromises.push ( Promise.resolve ( null ) )... | const allPromises = [ ] ; const selected = { sectionA : true , sectionB : false , sectionCIds : [ 1 , 2 , 4 ] , } ; if ( selected.sectionA ) { allPromises.push ( getSectionADataFromDbPromise ( ) ) ; } if ( selected.sectionB ) { allPromises.push ( getSectionBDataFromDbPromise ( ) ) ; } if ( selected.sectionCIds.length >... | The proper ways to stack optioned promises |
JS | first using var the second using this | function testCode ( some ) { var something = some ; } function testCode2 ( some ) { this.something = some ; } | What 's the difference between a 'var ' declared variable and 'this ' created property in Javascript ? |
JS | How can I convert this js object into a string array , sorted by value , like so : | var obj1 = { `` user1 '' :28 , `` user2 '' :87 , `` user3 '' :56 } ; [ `` user2 '' , '' user3 '' , '' user1 '' ] | How to convert a associative array into a sorted string array ? |
JS | The following JavaScript causes the runtime to hang on Chrome ( v80.0.3987.116 ) and Firefox ( v72.0.2 ) on OSX 10.15.2.Why ? Note that I am marking the iterator function as async . | const iterable = { async * [ Symbol.iterator ] ( ) { yield 'one ' } } console.log ( [ ... iterable ] ) | Why does this async generator cause the JavaScript runtime to hang ? |
JS | Do you know if there is a clever way to comment a block of code containing a regexpthat contains */ ? For instance I found myself commenting a block containing this instruction : But if I comment the block : then javascript interpret the regexp as comment closing and can not parse the file . I tryied to put // in front... | ... messageParser.run ( 'messageFetched ' , /.*/ ) ; ... /*messageParser.run ( 'messageFetched ' , / . */ ) ; */ | How to comment a block containing regexp |
JS | I have a enum in my C # code and i want to get names from enum in my jQuery validate rules . Enum : Validate : This really works , but I want make something like this : In C # I can get names in this way : How can I make it in javascript ? Thanks for advice ! | public enum EnumItemField { Zero = 0 , One = 1 , Two = 2 , Three = 3 , Four = 4 , Five = 5 , } function updateFieldStatus ( ) { } $ ( document ) .ready ( function ( ) { $ ( `` # IntegrationService '' ) .validate ( { rules : { //Set range of Start `` config.EnumFormat [ Zero ] .Start '' : { required : true , digits : tr... | How to use a C # enumeration in Javascript |
JS | I have a simple question as part of a form . If the user answers `` Yes '' , they are given the option to enter more details.When a user does answer `` Yes '' , and enters more detail in the textarea , on submit it returns empty . I ca n't figure out why . I feel like this is probably something small that I 'm missing.... | < form > < div id= '' name-form '' > < label for= '' name '' > < strong > Is this the correct name ? < /strong > < /label > < input type= '' radio '' value= '' yes '' name= '' name-choice '' / > Yes < input type= '' radio '' value= '' no '' name= '' name-choice '' / > No < /div > < input id= '' submit '' type= '' submi... | Textarea field returns empty upon submit |
JS | Google provides the following code snippet in the `` Adding analytics.js to Your Site '' guide : Is this piece of code initializes Google Analytics ? How ? | window.ga=window.ga||function ( ) { ( ga.q=ga.q|| [ ] ) .push ( arguments ) } ; ga.l=+new Date ; | What is the meaning of Google Anlaytics async tracking snippet ? |
JS | I understand how to do this by problem by hand , but I want to create a Javascript program to complete this for ( c , r ) , with c being containers and r being rocks.SettingYou have 4 indistinguishable rocks of all the same type . You also have 10 containers . Each container can hold 0 rocks or 1 rock . All 4 rocks nee... | 11110000001110100000111000100000000011110101010100 | Program to solve Circular Combinatorics Program Problem |
JS | In .NET I can format number by this code : Result : res= 1,234,567.89I want using this format `` # , # # 0.00 '' in JavaScript . Does it support formatting numbers by string format ? | Dim num = 1234567.8933Dim res = num.ToString ( `` # , # # 0.00 '' ) | Does JavaScript support formatting numbers by string format ? |
JS | I m learning JavaScript and I spent all day on this , I hope you could help me ^^I have X select elements like below : When I choose one option in each X elements , I need to increment by one except for the first one 'Sélectionnez.. ' . When I choose this one , I need -1.My problem is , when I choose 'Email ' and then ... | < select class= '' custom-select select-group mb-3 '' id= '' name_typage_0 '' > < option class= '' select-items '' value= '' '' selected > Sélectionnez.. < /option > < option class= '' select-items '' value= '' designation '' > Désignation < /option > < option class= '' select-items '' value= '' email '' > Email < /opt... | Stop incrementation when selecting a new option in select element |
JS | My English is not good , but I will try my best to explain my question simply.Description : Alert result is 1 , I do n't why , I think this should be 2015 to alert . | var book = { } ; Object.defineProperties ( book , { _year : { value : 1 } , edition : { value : 23 } , year : { get : function ( ) { return this._year ; } , set : function ( newValue ) { if ( newValue > 2004 ) this._year = newValue ; } } } ) ; book.year = 2015 ; alert ( book.year ) ; | How to use setter and getter in javascript , I met a error |
JS | The following code : produced the following output : and I would just kindly like to know why . ( I 'm aware now that the following code : will give me my desired output : ) | var arr1 = [ 1,2,3 ] ; var obj1 = { } ; for ( var j = 0 ; j < arr1.length ; j++ ) { if ( obj1 [ j.toString ( ) ] ) obj1 [ j.toString ( ) ] = obj1 [ j.toString ( ) ] .push ( j ) else obj1 [ j.toString ( ) ] = [ ] .push ( j ) ; } obj1= > { ' 0 ' : 1 , ' 1 ' : 1 , ' 2 ' : 1 } var arr1 = [ 1,2,3 ] ; var obj1 = { } ; for ( ... | javascript : unexpected behavior pushing into empty array |
JS | So I have a JSON feed and i 'm simply trying to print out some values.My Javascript below sort of works . But it does n't look very 'correct ' . Is there a better way of doing this please ? JSONJavaScript | { `` info '' : [ { `` lon '' : -2.1 , `` lat '' :55.2 } , { `` lon '' : -2.12 , `` lat '' :55.23 } ] } var jsonURL = `` url here '' ; $ .getJSON ( jsonURL , function ( json1 ) { $ .each ( json1 , function ( key , data ) { $ .each ( data , function ( key , data ) { var latLng = new google.maps.LatLng ( data.lat , data.l... | Logging JSON values using $ .each |
JS | Say I have an array of Person objects : and I have a function which can sort an array of strings case insensitively : Is there any straightforward way to combine my existing sort function with Array.prototype.map to sort the people array just using the name key ? I.e . it would produceDoing it by hand is not hard in th... | var people = [ { name : `` Joe Schmo '' , age : 36 } , { name : `` JANE DOE '' , age : 40 } ] ; function caseInsensitiveSort ( arr ) { ... } var people = [ { name : `` JANE DOE '' , age : 40 } , { name : `` Joe Schmo '' , age : 36 } ] ; people.sort ( function ( a , b ) { return a.name.localeCompare ( b.name ) ; } ) ; | Sort an array by the contents of another in JavaScript |
JS | Consider the following two programs : andRun node then enter .load works.js . Everything seems happy . Now exit node.Run node again and enter .load fails.js.On my machine loading fails.js interactively leads the node process to consume over 1GB of RAM and 100 % CPU , and the final statement blocks the interpreter forev... | // works.jsvar buffer = new ArrayBuffer ( 16777216 ) ; var HEAP8 = new Int8Array ( buffer ) ; // fails.jsvar HEAP8 ; var buffer = new ArrayBuffer ( 16777216 ) ; HEAP8 = new Int8Array ( buffer ) ; node works.js # exits normallynode fails.js # exits normally | Why does Node sometimes hang when allocating Int8Array ? |
JS | I had thought that the d3.js append function returns the object appended to a selection , but I find the following two code blocks give different results : Which does not seem to translate the graph group , offsetting it by a left and top margin and : which does.What do n't I understand about the way this works in SVG ... | var svg = d3.select ( `` body '' ) .append ( `` svg '' ) .attr ( `` width '' , fig_width ) .attr ( `` height '' , fig_height ) ; svg.append ( `` g '' ) .attr ( `` class '' , `` graph '' ) .attr ( `` transform '' , `` translate ( `` + graph_margin.left + `` , '' + graph_margin.top + `` ) '' ) ; var svg = d3.select ( `` ... | What is the difference between these two code blocks in d3.js |
JS | Nowadays , when you call a function 's .toString ( ) , browsers return the function 's original declaration.But I remember that Firefox used to return an optimized version , eg.On which browsers is it safe to use this feature ? | function fn ( ) { return 2+3 ; } fn.toString ( ) // Used to give : function fn ( ) { return 5 ; } | When did Firefox change its Function.prototype.toString ( ) behaviour ? |
JS | I build an action which plays some audio file . I want to add ability for user to listen from the place he stopped . In Alexa there is an offset parameter which I could specify . Is there anything similar for Google Assistant ? For now I start playback like that : I know about MediaObject but there is no parameter to s... | conv.ask ( new MediaObject ( { name : 'some file ' , contentUrl : AudioFileUrlProvider.generateTempUrl ( ) , description : 'some description ' , } ) ) ; | How to setup audio stream offset |
JS | I have a site with several svg icons and svg logo that I have to animate.For a better readability , I use a sprite system on an external file.I use XMLHttpRequests to load sprites at the beginning of the request.as soon as I use queryselector to select an element and animate it , this one is undefinedfor exampleand her... | function getSprites ( url ) { var ajax = new XMLHttpRequest ( ) ; ajax.open ( `` GET '' , url , true ) ; ajax.send ( ) ; ajax.onload = function ( ) { var div = document.createElement ( `` div '' ) ; div.innerHTML = ajax.responseText ; document.body.insertBefore ( div , document.body.childNodes [ 0 ] ) ; } } getSprites ... | External SVG sprites and .childnodes |
JS | Since functions are given `` global context '' when not accessed as a property of an object [ 1 ] , the following has the same quirk : because it 's just syntactic sugar for : which seems slightly counter-intuitive to me since I now have to re-bind or forgo the sugar.Is there a way to change this behaviour so that the ... | const foo = ( { bar } ) = > { bar ( ) ; // this === window } const foo = ( x ) = > { var bar = x.bar ; bar ( ) ; } | How to bind a method to original context when assigned to variable |
JS | I 'm trying to figure out why the values in my chart are not coming out correctly . When I log the values of learningLanguages [ j ] .count++ as it is looping they are accurate . However , when I log n in the map function in the chart $ .map ( nativeLanguages , function ( n ) { ... } ) , the counts are all incorrect ( ... | var getLanguages = $ .get ( '/languages.json ' , function ( languages ) { // top level language arrays learningLanguages = [ ] nativeLanguages = [ ] // object constructor that correctly formats the language objects function Language ( lang ) { this.language = lang ; this.count = 0 ; } // Loop through the languages , cr... | Ca n't figure out why the values in my objects are changing |
JS | I spent whole day trying to figure out weather I use Promises wrongly.Is that anti-pattern ? Can I use async in promise like that ? Also is that wrong as well ? Assuming adding async makes it a promise by default , also if that 's the case , should I just return from function which will be same as resolve , and if I th... | export const myExample = ( payload ) = > { return new Promise ( ( resolve , reject ) = > { } ) } export const myExample = ( payload ) = > { return new Promise ( async ( resolve , reject ) = > { } ) } export const myExample = async ( payload ) = > { return new Promise ( ( resolve , reject ) = > { } ) } export const myEx... | JavaScript Promises confusion anti-pattern ? |
JS | So I have a box .box . That repeats a spinning animation infinitely.The animation is only applied when the box 's second class name is runningThe purpose of this is so that I can easily stop the animation via javascript . ( by removing the second class name . ) I would like it to smoothly transition from wherever it is... | @ keyframes spin { 0 % { transform : rotate ( 0deg ) ; } 100 % { transform : rotate ( 360deg ) ; } } .box.running { animation-name : spin ; | Transition out of animation ? |
JS | I am developing a vanilla javascript calculator from scratch . I was able to accomplish the separation between the numbers and operations but once I pass the arrays to another functions that function does n't work at all for some reason . Please note I 'm a self-learner and I 'm a beginner javascript developer so I 'm ... | //Index.js where the problem is// this the field to control the result textfieldvar textfield = `` `` ; //this function to copy the number/operations button to the textfiled//it worksfunction retunNumber ( val ) { console.log ( val ) ; if ( textfield ! = `` `` ) { textfield = textfield + val ; document.getElementById (... | function in javascript does n't work once being trigger ? |
JS | I have a ViewBag.List > where i have competition , and every competition has a list of teams.Example : List of { Premier League : [ Arsenal , Chelsea etc ] Bundesliga : [ Bayern Munchen , Wolfsburg etc ] I have 2 selects . When the user selects the first select ( competition ) , i want that the second select will have ... | function myFunction ( select ) { var sel = document.getElementById ( `` teams '' ) ; if ( select.value == 'Premier League ' ) { sel.innerHTML = `` '' ; @ foreach ( var team in ViewBag.List [ 0 ] ) // Premier League { @ : var x = document.createElement ( `` OPTION '' ) ; @ : x.setAttribute ( `` value '' , @ team ) ; @ :... | < select > for < select > c # to javascript |
JS | I 've created a global shortcut where Ctrl+Shift+I opens a detached DevTools window . However , when the DevTools window is minimised , pressing Ctrl+Shift+I does not do anything.I want to be able to restore/unminimise the minimised DevTools window by using the Ctrl+Shift+I shortcut . The .focus method usually works fo... | if ( focussedWindow.webContents.isDevToolsOpened ( ) ) { if ( focussedWindow.webContents.devToolsWebContents ! == null ) { focussedWindow.webContents.devToolsWebContents.focus ( ) ; } } | Electron : How to refocus/restore a minimised DevTools window |
JS | I have a menu in jQuery when you click on a link it opens up , but I want it so when you click somewhere else , anywhere else that is not the menu , it becomes hidden.At the moment I 'm binding a click event to But this seems like I 'm binding a click event to the entire minus the menu , is there a more efficient way o... | $ ( ' : not ( # the_menu ) ' ) | The best way to do : not in jQuery ? |
JS | This is my first question and I 'm so happy for thisI created a page with fullpage.js RoadmapI would create an animation with CSS3 , so I saw an easy tutorialI followed instructions and I pasted code to roadmap.htmlAnimation works well , but I do n't know why there are 14 rockets with blue brackground . You can see `` ... | < style > # outerspace { position : relative ; height:400px ; background : # 0c0440 url ( 'http : //www.the-art-of-web.com/images/rocket.gif ' ) ; color : # fff ; } div.rocket { position : absolute ; bottom:10px ; left:20px ; -webkit-transition:3s ease-in ; -moz-transition:3s ease-in ; -o-transition:3s ease-in ; transi... | Problems with CSS3 animation |
JS | I want to collapse category tree with multi hierarchy . I tried so many answers from stack , but it 's not working . Can anyone please help me ? I tried this code : https : //stackoverflow.com/a/30945775/7727479Actual Result : First display Test 1 and Test 3Then , click on Test 1 = > On click Test 2 and Test 8 should b... | $ ( document ) .ready ( function ( ) { var getChild = $ ( 'ul.categories ' ) .children ( 'li ' ) ; getChild.each ( function ( i , v ) { if ( $ ( v ) .data ( 'parentcategory ' ) == `` 0 '' ) { $ ( v ) .addClass ( 'active-collapse ' ) ; } } ) ; $ ( 'div.categories-list li ' ) .click ( function ( ) { var main_category = $... | HTML collapse/expand tree not working as expected |
JS | I have a bot running using botkit . I want to give a warning message that edited messages are ignored just when you 're talking directly to the bot so I 'm doing : The bot is in a room with many people so that those people can have `` access '' to the bot privately.Problem : When someone edits a message in the room , t... | controller.on ( 'message_changed ' , function ( bot , message ) { bot.reply ( message , `` : warning : Your edit was ignored . `` ) ; } ) ; | Ignore Slack edits in a Room but not directly to the bot |
JS | What is the way for having a graphical component ( more precisely a twitter.bootstrap icon ) in an html website calling a java script . One could either make a button and putting the icon on it , but this does not look nice IMHO.Or one could use the href tag , But what is the cleanest way of achieving this ? It would a... | < a href= '' # '' name= '' ad_fav '' onclick= CALLFUNCTION > < i class= '' icon '' > < /i > < /a > | Right way of triggering a javascript from html |
JS | I need to adapt my Javascript RegEx to match certain patterns only . The RegEx is used in the html5 pattern attribute to validate an input field.I want to accept alphanumeric pattern of the following types only : A-AAAA or BB-BBB ( the intended pattern is : 1 digit before the `` - '' , and 4 digits after the `` - '' , ... | / ( [ \w ] { 1,2 } ) ( - ( [ \w ] { 3,4 } ) ) /g | JS RegEx to match certain patterns only |
JS | I have the following classWhy do I only see the changed value if I access the w object through a function ? | function Temp ( ) { var isHot=false ; return { setHot : function ( v ) { isHot=v } , getHot : function ( ) { return isHot ; } , hot : isHot } } var w = new Temp ( ) ; w.setHot ( true ) ; w.hot ! == w.getHot ( ) | Can someone explain odd JavaScript with objects ? |
JS | JavaScript code : PHP code 1 : PHP code 2 : What causes the difference between PHP and JavaScript assignment operators ? Is it operator precedence related ? I want to know what the reasons are . Thanks ! | var a = 1 , b = 2 ; a = b + ( b = a ) * 0 ; // result a = 2 , b = 1 ; $ a = 1 ; $ b = 2 ; $ a = $ b + ( $ b = $ a ) * 0 ; // result $ a = 1 , $ b = 1 ; $ a = 1 ; $ b = 2 ; $ a = ( int ) $ b + ( $ b = $ a ) * 0 ; // result $ a = 2 , $ b = 1 ; | About JavaScript and PHP assignment operators : Why the different results ? |
JS | Is it possible to bind ngOptions to a value outside of the $ scope ? I have a set of enums that will be automatically rendered as javascript . These are currently not part of `` the angular domain '' , but I want to bind a ngOptions to one of the arrays , and I would like to not have to copy the items into the scope ma... | var NS = NS || { } ; NS.Sub = NS.Sub || { } ; // This is auto-generated : NS.Sub.enums = { `` deliveryStatus '' : [ { `` id '' :1 , '' label '' : '' Delivered '' } , { `` id '' :2 , '' label '' : '' Expected '' } , { `` id '' :4 , '' label '' : '' Failed '' } ] , '' documentType '' : [ { `` id '' :0 , '' label '' : '' ... | Bind ngOptions to array outside of scope |
JS | Greetings Stack Overflow ! First off , this is my first question ! I am trying to solve the selfDividingNumbers algorithm and I ran into this interesting problem . This function is supposed to take a range of numbers to check if they are self dividing.Self Dividing example : My attempt with Javascript.When comparing th... | 128 is a self-dividing number because 128 % 1 == 0 , 128 % 2 == 0 , and 128 % 8 == 0 . /* selfDividingNumbers ( 1 , 22 ) ; */var selfDividingNumbers = function ( left , right ) { var output = [ ] ; while ( left < = right ) { // convert number into an array of strings , size 1 var leftString = left.toString ( ) .split (... | Javascript Help - selfDividingNumbers Algorithm producing all 0 's |
JS | I 'm making a jQuery plugin that displays alerts on the page . The plugin itself inserts the alert markup into the DOM . Since the jQuery way is to make everything return this to maintain chaining , I 've run into an interesting issue I 'd like feedback on . I 'm trying to decide between the following two options.Optio... | $ ( `` # content '' ) .alert ( 'prepend ' , { type : 'error ' , message : 'This is an error ' } ) $ ( `` < div > '' ) .alert ( { type : 'error ' , message : 'This is an error ' } ) .prependTo ( `` # content '' ) | Which strategy makes more sense in this jQuery plugin ? |
JS | I have a 3D css wheel/cylindar animation that 's rotating on the x axis . My issue is the animation appears to move up and down outside of it 's container . Example GIF below ... The code for the above can be found here here : https : //jsfiddle.net/thelevicole/bkt0v1mc/The red pane is the segments container , this is ... | ( function ( $ ) { const $ wheel = $ ( '.wheel .wheel__inner ' ) ; const items = 28 ; const diameter = $ wheel.height ( ) ; const radius = diameter / 2 ; const angle = 360 / items ; const circumference = Math.PI * diameter ; const height = circumference / items ; for ( let i = 0 ; i < items ; i++ ) { var transform = ` ... | CSS 3D animated wheel off center |
JS | Hi experts here is my code and I 'm stuck how this keyword is adding property to a object.I know property added with this and Object.prototype is inherited to all objects but does both are equivalent i.e , this is also adding property to prototype ? If yes then why console.log ( carMaker.prototype.companyName ) is unde... | function carMaker ( ) { this.companyName='Lamborghini ' ; } let LamborghiniUrus = new carMaker ( ) ; carMaker.prototype.country= '' Italy '' LamborghiniUrus.price= '' 200000 '' ; | How does 'this ' keyword work in prototype chain ? |
JS | I have a rectangle that is animated using .transition ( ) and it takes 5 seconds ( .duration ( 5000 ) ) . I want to know if there is any way to specify a percentage under those 5 seconds , so the animation is executed from that percentage on.For example , with a duration of 5 seconds , if I specify a value of 50 % , I ... | d3.select ( `` # visualization '' ) .append ( 'svg ' ) ; var vis = d3.select ( `` svg '' ) .attr ( `` width '' , 800 ) .attr ( `` height '' , 614 ) .style ( `` border '' , `` 1px solid red '' ) ; var rectangle = vis.append ( `` rect '' ) .attr ( `` width '' , 100 ) .attr ( `` height '' , 70 ) .attr ( `` x '' , 0 ) .att... | If a transition lasts n seconds is it possible to start it at a specified percentage of that time ? |
JS | Is there a way how to alias function operator without too much overhead like eval ? I 'd like to writeinstead ofto strip some bytes in minified code . Just curious . | fn test ( ) { ... } function test ( ) { ... } | Can function operator be aliased ? |
JS | I want to generate an addition equation for a random number which is look likes 5+10+2 from a set of numbers i.e [ 1,2,5,10,50 ] .And the maximum number of elements in equation is 5.Is it possible in java script ? Thanks in advance . | var randomNumber = Math.floor ( Math.random ( ) * ( 10 - 1 + 1 ) ) + 1 ; var setOfNums = [ 1,2,5,10,50 ] ; var additionEquation ; //ex : for randomNumber = 28 ; additionEquation = 10+10+5+2+1 ; | How to generate an addition equation for a number using only required set of numbers ? |
JS | I 'm making a typescript npm package.It uses discord.js , but there 's two main version of discord.js : * discord.js 11.5 * discord.js v12.0.0-dev I 'd like my module to support both version . I mean , users can install the version of discord.js they want and the package will use the good code.For another project , in ... | const { version } = require ( `` discord.js '' ) ; if ( version === `` 12.0.0-dev '' ) { // code for v12 } else { // code for v11 } const { Guild , version } = require ( `` discord.js '' ) ; if ( version === `` 12.0.0-dev '' ) { Guild.iconURL ( ) ; // for v12 } else { Guild.iconURL ; // for v11 } | How to support several versions of the same module with typescript ? |
JS | I was just wondering if I could run this functions in a better way , I mean I do n't like the collection of functions in there : | setTimeout ( function ( ) { $ ( self.header_buttons_classes [ 0 ] ) .addClass ( self.animations [ 15 ] ) ; setTimeout ( function ( ) { $ ( self.header_buttons_classes [ 1 ] ) .addClass ( self.animations [ 15 ] ) ; setTimeout ( function ( ) { $ ( self.header_buttons_classes [ 2 ] ) .addClass ( self.animations [ 15 ] ) ;... | Can I run this nested functions in a better way ? |
JS | I 'm having a working live preview Script . But now i want that the field for phone and fax only are displayed , when there is an input in the form fields . But i guess there has to be an issue with the empty statement . Does anyone has an idea to fix this ? Thank you very much ! JS FiddleJS Fiddle Update # 1After a lo... | $ ( document ) .ready ( function ( ) { updatePreview ( ) ; $ ( ' # live-preview-form input , # live-preview-form textarea # live-preview-form select ' ) .bind ( 'blur keyup ' , updatePreview ) ; } ) ; function updatePreview ( ) { var contact = $ ( ' # lp-contact ' ) , company_name = $ ( ' # lp-company_name ' ) , compan... | Jquery if empty loop in live preview |
JS | My understanding was these two are always equal ( as in the first console.log statement ) .But , while doing some tweaks I found this surprising result ( second console.log statement ) .Can someone please clear up my understanding about the relationship between prototype and __proto__ . Thanks in advance ! | function Product ( name , price ) { this.name = name ; this.price = price ; } const p1 = new Product ( 'Pen ' , 20 ) ; const p2 = Object.create ( p1 ) ; console.log ( p1.constructor.prototype === p1.__proto__ ) ; // trueconsole.log ( p2.constructor.prototype === p2.__proto__ ) ; // false | Why is obj.constructor.prototype not always equal to obj.__proto__ ? |
JS | TL : DR ; Is it possible to make a property of object to be invocable ( as a function ) only ? What i mean by thisI tried to do this with Proxy and handler.get trap , but i have no clue how to capture whether it is a function call or just property access , I have also checked handler.apply but this also does n't seems ... | class Foo { bar ( value ) { return value } } let newFoo = new Foo ( ) console.log ( newFoo.bar ( 123 ) ) // should work fine as function is invokedconsole.log ( newFoo.bar ) // here i need to throw or display an error instead of returning value class Foo { bar ( value ) { return value } } const proxied = new Proxy ( ne... | Make object or class property only invocable |
JS | I have below Basic Javascript to reverse the number which work when I use while ( ! no == 0 ) But Does n't work when I use while ( ! no === 0 ) I have tried in the console for parseInt ( 0 ) which returns number only and my no is already number so why === is not working , Can someone help and explain me better ? | function findRepeated ( number ) { var a , no , b , temp = 0 ; no = parseInt ( number ) ; while ( ! no == 0 ) { a = no % 10 ; no = parseInt ( no / 10 ) ; temp = temp * 10 + a ; } return temp ; } console.log ( findRepeated ( 123 ) ) ; | Comparision is not working in Javascript with Strict Equal |
JS | I have text area controls in my page and I had code it such way that when user click on text area or hit 'ENTER ' key that time it will create bullet-list in text area . But problem is that if user click on text area and it will create bullet-list but if user does not type anything in text area then it should get empty... | < textarea name= '' MondayAcomp '' id= '' MondayAcomp '' cols= '' 45 '' rows= '' 5 '' onKeyDown= '' if ( event.keyCode == 13 ) return false ; '' onKeyUp= '' bulletOnEnter ( this.id ) '' onFocus= '' onfoc ( this.id ) '' onBlur= '' onFocOff ( this.id ) '' style= '' margin : 0px ; width : 200px ; height : 219px ; '' > < /... | I need help to empty text area on particular conditions |
JS | I have this array [ [ 1,2,3 ] , [ 4,1,6 ] , [ 1,3,2 ] , [ 1,2,4 ] , [ 3,1,2 ] , [ 4,6,1 ] , [ 9,9,9 ] ] and I want a function that do this : [ [ 1,2,3 ] , [ 4,1,6 ] , [ 1,2,4 ] , [ 9,9,9 ] ] .This function removes all subarray with the same value.I thought about a filter like this .filter ( el = > el.filter ( value = >... | [ [ { name : 'Dofawa ' , item_type : 'Dofus ' , level : 6 } , { name : 'Dofus Cawotte ' , item_type : 'Dofus ' , level : 6 } , { name : 'Dofus Kaliptus ' , item_type : 'Dofus ' , level : 6 } ] , [ { name : 'Dofawa ' , item_type : 'Dofus ' , level : 6 } , { name : 'Dofus Emeraude ' , item_type : 'Dofus ' , level : 6 } ,... | How to remove all combination with the same element in subarray from array ? |
JS | Unsure if my question 's title is correctly worded , please correct me if it 's wrong.I 'm using TypeIt to display dialogues . Right away an example of its usage for context : Preview of example on codepen : https : //codepen.io/carpenumidium/pen/yLBawrZI 'm trying to display a random dialogue from an array but my meth... | new TypeIt ( ' # myElement ' , { // options } ) .type ( `` This is a sentence . `` ) .pause ( 500 ) .type ( `` A second sentence after waiting 500 milliseconds '' ) .go ( ) ; var dialogue = new TypeIt ( ' # dialogues ' , { speed : 50 , waitUntilVisible : true , cursor : false } ) ; var dialogueText = [ dialogue.type ( ... | Chaining properties using data from array |
JS | I have an application ( HTML5 , JavaScript , Jquery , jquery Mobile ) with a slider . The handle can be moved via touch and you can navigate through the years 1861 to 2000 . There are symbols on my map which are visible/non visible depending on the year . See my example image.I also want the handle to move , when the u... | function moveLeft ( ) { var slider1 = $ ( `` # slider '' ) .val ( ) ; var $ slider = $ ( `` # slider '' ) ; slider1++ ; $ slider.val ( slider1 ) .slider ( `` refresh '' ) ; var wert1 = slider1 ; var start = new Date ( ) .getTime ( ) ; //start = hideLayer2 ( wert1 , start ) ; $ ( ' # jahr ' ) .text ( wert1 ) ; var $ aus... | How to trigger any of the arrow keys |
JS | I have an array like this : I would like to order this array based on a other given array like this : The preferred result would be : It does n't matter on what index the words that are not in the order array are placed . It 's not guaranteed that the words in the order array will be in the unordered arrayCurrent Code ... | unorderedArr = [ 'pear ' , 'apple ' , 'banana ' , 'peach ' , 'pineapple ' ] ; order = [ 'peach ' , 'apple ' , 'pineapple ' ] orderedArr = [ 'peach ' , 'apple ' , 'pineapple ' , 'banana ' , 'pear ' ] ; const orderedArr = [ ] unorderedArr.forEach ( word = > { switch ( word ) { case 'peach ' : orderedArr.push ( word ) ; b... | Order an array of words based on another array of words |
JS | I 've been staring at this answer for a while and I ca n't wrap my head around it : https : //stackoverflow.com/a/23699009/3658800.To summarize : Only property reads search the prototype chain , not writes . So when you setIt does n't look up the chain , but when you set there 's a subtle read going on within that writ... | myObject.prop = '123 ' ; myObject.myThing.prop = '123 ' ; | Why do property writes not consult the prototype chain in Javascript ? |
JS | My string is : I managed to formulate a regular expressionBut trainDetails are null or are empty.All I am trying to do is to get the train name and the train number within the span element.Any pointers where I am doing wrong ? | < div > ( blah blah blah ) -- - > quite big HTML before coming to this line. < b > Train No . & amp ; Name : < /b > < /td > < td style= '' border-bottom:1px solid # ccc ; font:12px arial '' > < span > 12672 / SOUTH TRUNK EXP < /span > < /td > var trainDetails = new RegExp ( `` < b > Train No . & amp ; Name : < /b > < /... | What am I doing wrong in parsing this regular expression in javascript ? |
JS | I do not understand Javascript interpretation of the next lines of code : Why is an array taken as the value 0 ? | var a = [ `` value '' ] ; console.log ( a [ 0 ] ) ; // valueconsole.log ( a [ [ 0 ] ] ) ; // valueconsole.log ( a [ [ [ 0 ] ] ] ) ; // value// ... | Javascript index of array is array |
JS | While trying to debug some faulty piece of JavaScript , I found a line that looks like an obvious mistake in a source file : What I do n't undestand is why this statement behaves differently in all browsers.In Chrome , I get a ReferenceError and the whole script is not run.In Firefox , I get a SyntaxError and the whole... | false++ ; | Why does false++ produce a SyntaxError in Firefox but a ReferenceError in Chrome ? |
JS | Asuming I have something likeHow could I get the 24a34b83c72 ID using pure javascript ? I know that it 's always after the questions/ part and that regardless if it contains a number or symbol , it needs to end before the next / . I tried things like ; url.substring ( url.lastIndexOf ( 'questions/ ' ) ) But that result... | var url = 'http : //stackoverflow.com/questions/24a34b83c72/js-regex-get-values-between-two-characters ' | How can I get a value from an URL ? |
JS | I 'm using the above code to perform an action on every list item but list dividers are also proccing this event.I managed to exclude my close button using however I ca n't stop it from occurring on list dividers . I 've tried to no availHere 's a JSFiddle with the problem : http : //jsfiddle.net/2g3w5/ | $ ( document ) .on ( `` click '' , `` li '' , function ( ) { alert ( `` A list item was clicked '' ) ; } $ ( document ) .on ( `` click '' , `` li '' , function ( ) { if ( this.id ! == `` closeButton '' ) { alert ( `` A list item was clicked '' ) ; } } ) ; $ ( document ) .on ( `` click '' , `` li '' , function ( ) { if ... | Ca n't stop list dividers being treated as list items |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.