lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
In the following , code unhandledRejection does n't get fired for p2 , even though it also gets rejected , albeit later than p1 : If I change the commented line like this : ... then unhandledRejection does get fired for p2 , as expected . The same behavior is observed for Promise.all ( ) .Thus , Promise.race and Promis...
process.on ( 'unhandledRejection ' , ( reason , promise ) = > console.log ( ` unhandledRejection : $ { reason } ` ) ) ; async function delay ( ms ) { await new Promise ( r = > setTimeout ( r , ms ) ) ; } const p1 = async function f1 ( ) { await delay ( 100 ) ; throw new Error ( `` f1 '' ) ; } ( ) ; const p2 = async fun...
Is it a documented behavior that Promise.all and Promise.race effectively make all promises `` handled '' ?
JS
Have to mention : I know a bit JavaScript but I 'm not very deep into it.Always considered this the correct way to check if a property is available on an object : Yesterday I 've seen code in which this technique was used : Are both techniques equivalent ? Or do they distinguish ?
if ( window.console ) { // doSomething } if ( 'console ' in window ) { // doSomething }
Property detection : Using 'in ' versus trying to access property
JS
I would like to prepend the word `` custom '' to a list of host-names whose subdomains can be separated by some separator.Examples : These strings appear inside a document with more content , so I am trying to solve this problem using regular expressions and JavaScript 's string replace function.The list of hostnames a...
news.google.com - > custom.news.google.comnews/google/com - > custom.news.google.comdev.maps.yahoo.fr - > custom.dev.maps.yahoo.frdev/maps/yahoo/fr - > custom/dev/maps/yahoo/fr const myRegex = /news\.google\.com|news\/google\/com|dev\.maps\.yahoo\.fr|dev\/maps\/yahoo\/fr/ const myRegex = /news ( \. ) google\.com|news (...
How to avoid capturing groups if the captured match is empty ?
JS
I have two identical arrays : itemsOutput & itemsOutput2I want to delete those objects in the arrays with attributes.type = `` DIMENSION '' . I have found two different methods for doing so : Method 1Method 2Although both new arrays seem to have the same number of objects ( and in both , all objects with attributes.typ...
jQuery.each ( itemsOutput , function ( i , val ) { if ( val.attributes.type == `` DIMENSION '' ) // delete index { delete itemsOutput [ i ] ; } } ) ; console.log ( itemsOutput.length ) ; metrics = itemsOutput2.filter ( function ( el ) { return el.attributes.type === `` METRIC '' ; } ) ; console.log ( metrics.length ) ;
Remove objects from array - Two different approaches , two different results when consulting the length of each array
JS
I am receiving an erratic behavior of the events when I load two eventSources and one of them is defined with rendering : background.The generated JSONs are correct , since when defining the two eventSources with the normal rendering , everything works correctly.The indicated behavior includes these symptoms : Some Eve...
$ ( ' # workshifts_ocupations_calendar ' ) .fullCalendar ( { defaultView : 'agendaWeek ' , eventSources : [ { id : `` workshiftSource '' , url : ' < ? = base_url ( ) ; ? > turno/ajax_load_workshifts_by_installation/'+installation , editable : true , success : function ( ) { console.log ( `` turnos '' ) ; } } , { id : `...
Erratic behavior loading 2 JSON eventsources ( one must be background events )
JS
What 's the quickest way , from a readability/typing standpoint , to assign a value to a specific variable based on a related variable ? I 'm trying to avoid making one array for the state name and a another array for the abbreviation because the relationship is lost with separate declarations .
var abbrev ; if ( state=='Pennsylvania ' ) { abbrev='PA ' ; } else if ( state=='New Jersey ' ) { abbrev='NJ ' ; } else if ( state=='Delaware ' ) { abbrev='DE ' ; } //and so on ...
What 's the quickest way to assign a variables based on an array ?
JS
After I click divB1 , I create a button through b1.funB ( ) .After I click divB2 , I create a button througb b2.funB ( ) .Why can only newest button alert name ? I find that other button 's onclick function is null .
function B ( sName ) { this.name = sName ; } B.prototype = { instanceCreatButtonCount : 0 , funA : function ( ) { // alert instance 's name alert ( this.name ) ; } , funB : function ( ) { // create a button which clikced can alert this instance 's name through funA ; var that = this ; B.prototype.instanceCreatButtonCou...
Why can only newest button work ? I find that other button 's onclick function is null
JS
Can you please take a look at this demo and let me know why i am not able scroll the .post div with jquery and input range properly using percentage value like this
$ ( `` [ type=range ] '' ) .on ( 'input ' , function ( ) { var val = parseInt ( $ ( this ) .val ( ) ) ; $ ( '.post ' ) .animate ( { scrollTop : val+ '' % '' } , 5 ) ; } ) ; .post { overflow-x : hidden ; top:30px ; height:200px ; width:200px ; background-color : # EEE ; } .content { width:100 % ; height:3000px ; } input...
Not Able to Apply Percentage on scrollTop
JS
I 'm beginner at js/jquery.I want to code this structure with js/jquery : I have this code : Here is fiddle : https : //jsfiddle.net/ds6wj38k/2/I found a few similar questions like this and tried to add to my code but i ca n't adjust.Thanks .
< div class= '' box '' > < p > 1 < /p > < div class= '' content '' > < span > Lorem < /span > < /div > < /div > < div class= '' box '' > < p > 2 < /p > < div class= '' content '' > < span > Ipsum < /span > < /div > < /div > < div class= '' box '' > < p > 3 < /p > < div class= '' content '' > < span > Dolor < /span > < ...
Creating parent and child elements wit Js/jQuery
JS
i have table rows inside a table , and also another nested table rows inside each row , my problem is i can collapse and expand in the nested table rows , but when i try to expand in the main table , only the first row is expanded the rest ones are expanded by default when i launch the program , how can i fix it.this i...
tbody.collapse.in { display : table-row-group ; } .tigray { background-color : darkcyan ; } .zoba { background-color : forestgreen ; } < ! -- Latest compiled and minified CSS -- > < link rel= '' stylesheet '' href= '' https : //maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css '' > < ! -- jQuery library -- ...
how can i collapse all table rows
JS
Suppose I have this function below : It prints : I expect that it will print reject 1 ... 10.How can I achieve this ?
var a = 0 ; function test ( ) { return new Promise ( function ( resolve , reject ) { a++ ; if ( a < 10 ) { test ( ) reject ( a ) } else { resolve ( a ) } } ) } test ( ) .then ( function ( a ) { console.log ( 'resolve ' , a ) } ) .catch ( function ( a ) { console.log ( 'reject ' , a ) } ) reject 10
Get Out of Reject promise recursion in Javascript
JS
How do I get every single record of an array string substring ? Example : I tried to add substring : How do I get unique records by comparing the first n characters ?
sourcefiles = [ ' a.pdf ' , 'a_ok.pdf ' , ' a.csv ' , 'b_ok.csv ' , ' b.csv ' , ' c.pdf ' ] var uniq = [ ... new Set ( sourcefiles ) ] ; //I want the output to be : a , b , cconsole.log ( uniq ) sourcefiles = [ ' a.pdf ' , 'a_ok.pdf ' , ' a.csv ' , 'b_ok.csv ' , ' b.csv ' , ' c.pdf ' ] var uniq = [ ... new Set ( source...
How do I get unique records by comparing the first n characters ?
JS
My test string contains 4 instances of an open square bracket and a closed square bracket , so I would like the following regular expression to return 4 matches , but it only returns 1 .
const test = `` sf [ [ [ [ asdf ] ] ] ] asdf '' const regExp = new RegExp ( /^.*\ [ .*\ ] . * $ / , `` g '' ) ; const matches = test.match ( regExp ) .length ; console.log ( matches ) ;
Regular Expression Total Matches on Instances
JS
I noticed I was hitting the 10,000 unit quota limit for the YouTube data api which does n't seem right as I 'm only pulling playlist videos for my app.Here 's what I 'm talking about.I checked the Google Developer 's console and saw that my unit usage was going up , so I removed the app from heroku and got a new key , ...
import React , { Component } from 'react'import { gapi } from 'gapi-script ' ; import '../css/YouTube.css'import { Animated } from `` react-animated-css '' ; import Spinner from 'react-bootstrap/Spinner'import Button from 'react-bootstrap/Button'import { FiArrowUpCircle } from `` react-icons/fi '' ; export default clas...
Massive spike in YouTube Data API queries
JS
Toggle works perfectly fine , but whatever is inside the if statement does n't get executed when # button1content is no longer visible . boo . It could be another part of my code that is messing it up , but I only want to know if there is anything wrong with this .
$ ( ' # buttons1 ' ) .on ( 'click ' , function ( event ) { $ ( ' # button1content ' ) .toggle ( 'show ' ) ; var wasVisible = $ ( `` # button1content '' ) .is ( `` : visible '' ) ; if ( ! wasVisible ) { $ ( `` # buttons1 '' ) .css ( `` opacity '' , `` 0.5 '' ) ; } } ) ;
jquery . something wrong with syntax ?
JS
I have fairly lot of data in this formrepresented using javascript types as : I want to convert this into this form : I tried implementing it as : But this is slow for the size of the table I have . Is there any faster way to do this ?
A B C D -- -- -- -1 2 3 45 6 7 89 1 2 3 df = { A : [ 1,5,9 ] , B : [ 2,6,1 ] , C : [ 3,7,2 ] , D : [ 4,8,3 ] } [ { A:1 , B:2 , C:3 , D:4 } , { A:5 , B:6 , C:7 , D:8 } , { A:9 , B:1 , C:2 , D:3 } ] keyes = [ `` A '' , `` B '' , `` C '' , `` D '' ] getrow = ( i ) = > Object.assign ( ... keyes.map ( ( k ) = > ( { [ k ] : ...
Create array of objects using arrays of values
JS
I 'm thinking about making my own JavaScript client library , and I like the way Firebase formats requests . I 'm trying to understand whats going on . From looking at the web guide here I found the below code : I can see that ref is equal to a function called Firebase , and usersRef is equal to ref.child.I 'm imaginin...
var ref = new Firebase ( `` https : //docs-examples.firebaseio.com/web/saving-data/fireblog '' ) ; var usersRef = ref.child ( `` users '' ) ; usersRef.set ( { alanisawesome : { date_of_birth : `` June 23 , 1912 '' , full_name : `` Alan Turing '' } , gracehop : { date_of_birth : `` December 9 , 1906 '' , full_name : `` ...
Mimic Firebase client library 's structure and patterns
JS
I have a submenu with Routes in my /About.This submenu is called AboutMenu and is present at all pages under /About like = > /About/Company and /About/Info . An exercise example shows < Route component= { AboutMenu } / > with activeStyle= { match.isExact & & selectedStyle } > and i just used < AboutMenu / > and added e...
export const AboutMenu = ( props ) = > { return ( < div > < li > < NavLink exact to='/About ' activeStyle= { activeStyle } > Company < /NavLink > < /li > < li > < NavLink to='/About/History ' activeStyle= { activeStyle } > History < /NavLink > < /li > < li > < NavLink to='/About/Vision ' activeStyle= { activeStyle } > ...
Why < Route component= { Menu } / > instead of < Menu / > ?
JS
I am not sure how to call/frame this question title , but can anyone explain me what does the below code do ? I am seeing a second ( ) with app being passed , what does that do ? https : //github.com/couchbaselabs/restful-angularjs-nodejs/blob/master/app.jsTo my surprise , in the code above the variable routes is not a...
var routes = require ( `` ./routes/routes.js '' ) ( app ) ;
function ( ) ( ) in javascript
JS
I have an array looking like this : How can I shift its values while maintaining the order . For instance , I 'd like to start it with 'd ' :
arr = [ ' a ' , ' b ' , ' c ' , 'd ' , ' e ' , ' f ' ] ; new_arr = shiftArray ( arr , 'd ' ) ; // = > [ 'd ' , ' e ' , ' f ' , ' a ' , ' b ' , ' c ' ]
Shift array by value , keep sorting in order
JS
Okay , I 'm having trouble making two text values showing up within the same list item ( one < input > , one < textarea > ) Is this possible ? I 'm trying to create a simple diary/log application , in which you can add a title ( optional ) and the content of the post entry itself , press submit and have it create a lis...
< html > < head > < title > WriteUp < /title > < /head > < body > < div id= '' textWrap '' > < div class= '' border '' > < h1 > Start Writing < /h1 > < br / > < input id= '' title '' placeholder= '' Title ( Optional ) '' > < textarea rows= '' 4 '' cols= '' 50 '' type= '' text '' id= '' entry '' maxlength= '' 500 '' pla...
Making 2 text values show up within 1 list item
JS
i am load multiple php file using .load ( ) function . all file are load for some time but php file not load for one time his load for by one by one.. so plz how is ? ? ?
$ ( ' # demo ' ) .html ( ' < img src= '' /parcel-pricer/img/ajax-loader.gif '' style= '' margin-left:50px ; width:20 % ; margin-bottom:10px ; '' > ' ) ; $ ( ' # demo ' ) .show ( ) ; $ ( ' # demo ' ) .load ( 'fast.php ? send='+send+ ' & delv='+delv+ ' & quant='+quant+ ' & weight='+weight+ ' & length='+length+ ' & width=...
how to Loading php file one by one ?
JS
I have a multistep form in my project , the first step of which has a javascript extend field function where a user can add additional fields . If the user goes to the next step , the data is of course stored in Session until final submission . However , the extended form will not be remembered . If the user goes back ...
var counter = 0 ; function moreFields ( val1 , val2 , val3 ) { counter++ ; var newField = document.getElementById ( val1 ) .cloneNode ( true ) ; newField.id = `` ; newField.style.display = 'block ' ; var newFields = newField.querySelectorAll ( ' [ name ] , [ id ] , [ for ] , [ data-display ] ' ) ; for ( var i=0 ; i < n...
How to remember a form is extended ?
JS
I work with filtering , and i have issues , i have 4 option input in which i have some data which i need to filter in table , for now i filter data only for one column , but problem is if i will add one more filter , script will not work , and filter data from the last selected value . But i need if i have 2-4 selected...
$ ( `` # cancelFilters '' ) .hide ( ) ; $ ( ' # filterButton ' ) .click ( function ( ) { getSelectedVal ( ) filterData ( ) filters = [ ] ; $ ( `` # cancelFilters '' ) .fadeIn ( ) ; } ) ; var filters = [ ] ; function getSelectedVal ( ) { var materialCode = $ ( ' # materialCode option : selected ' ) .text ( ) var plantCo...
Filtering data in columns from options use jQuery
JS
I know I 'm going to feel dumb at the end of this , but I 've been struggling with this ... This works , comparing two strings that are the same and finding a match . But my jshint tells me to use this operator === which I understand ( from here ) to mean that types are also checked.Substituting the === my test fails ,...
if ( user._id == req.params.id ) { console.log ( `` match '' ) ; } else { console.log ( `` ' '' + user._id + `` ' does not match ' '' + req.params.id + `` ' '' ) ; }
Why are these two strings == but not ===
JS
I have a main page that I have loaded another page on it via ajax when document is ready , also I have a button that when I click It I shows an alert and , I have that button in the second page too . but when i click on it in that page that code does not work ? how can i solve this problem ? because I do not want to re...
< html > < head > < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js '' > < /script > < /head > < body > < div class= '' captcha '' style= '' border:1px solid red ; '' > < /div > < div class= '' details1 '' > cccc < /div > < script > $ ( document ) .ready ( function ( e ) { $ ( `` .capt...
Second page does not work with Codes in the first page
JS
I 'm using Node v12.14.1 on Windows 10 in cmd.When assigning the value of an undefined function to a variable : I get : Which is fine . But when I try : I now get : And when I try : I get : So , a variable declared using let , when assigned the value of an undefined function , has its identifier already declared , and ...
let a = f ( ) ; Thrown : ReferenceError : f is not defined a = 2 ; Thrown : ReferenceError : a is not defined let a = 2 ; Thrown : SyntaxError : Identifier ' a ' has already been declared
Weird ( let ) variable assignment behavior in node repl - ca n't assign values
JS
Some background : I am working through FreeCodeCamps Front-End Development projects and this project represents a Random Quote Machine.I would like to keep the author hidden for each quote , but at the moment , the `` Click to Reveal '' button only reveals an author every other quote ... https : //codepen.io/DecisiveIn...
$ ( document ) .ready ( function ( ) { var url = `` https : //api.forismatic.com/api/1.0/ ? method=getQuote & key=1 & lang=en & format=jsonp & jsonp= ? `` ; $ ( `` # refreshButton '' ) .on ( `` click '' , function ( ) { $ .getJSON ( url , function ( json ) { var jsonQuote = json.quoteText ; var jsonAuthor = json.quoteA...
Why is my .on ( `` click '' ) function for the AuthorButton only returning my variable every other quote ?
JS
I applied value to each of my radio , for each of my forms . Point is , I need to set the sum of all of them together . I thought I could simply go and set a simply function as setting the value of each text area for each form in an addition in my function so the total would be shown but it seems like it 's not working...
( function ( ) { var oForm = document.forms ; oForm [ 0 ] .querySelector ( `` input [ type='radio ' ] '' ) .addEventListener ( `` click '' , sommButton , false ) ; } ) ( ) function sommeButton ( ) { var aSomme1 = document.forms [ 0 ] .tEx1 ; var aSomme2 = document.forms [ 1 ] .tEx2 ; var aSomme3 = document.forms [ 2 ] ...
How to have the sum of 3 different value in one text area
JS
In javascript , we often see code like the following to set a default parameter when we do n't care to ignore falsey values.Occasionally though , when reading code , I 'll come across the following variation : Can someone explain to me the use case for this ?
function SomeObject ( param ) { this.param = param || { } ; } function SomeObject ( param ) { this.param = param = param || { } ; }
Javascript default parameter with extra assignment
JS
I have one question with my code.I have created this DEMO from jsfiddle.netWhen you click the red div then the menu will opening but if you click the menu items the menu area will not closing . What do i need to close the menu area when clicked the menu ? JS
< div class= '' p_change '' tabindex= '' 0 '' id= '' 1 '' > < div class= '' pr_icon '' > < div class= '' icon-kr icon-globe '' > < /div > CLICK < /div > < div class= '' pr_type '' > < div class= '' type_s change_pri md-ripple '' data-id= '' 0 '' > < div class= '' icon-pr icon-globe '' > < /div > 1 < /div > < div class=...
Menu field is not closing , when clicked on menu
JS
What I 've done is loaded some HTML from a file and I am attempting to modify some elements within that HTML.The initialization looks like this : With player_layout.html looking like this : I then want to modify some of the elements , specifically classes . An example of the way I was initially doing this is : This was...
var id = player_info [ `` ID '' ] ; $ ( `` # main_container '' ) .append ( $ ( `` < div / > '' ) .attr ( { class : `` player_container '' , id : `` player_ '' + id } ) .css ( `` display '' , `` none '' ) ) ; // Add all information to the player containervar player_container = $ ( `` # player_ '' + id ) ; player_contain...
Trouble setting the HTML of a variable in JQuery
JS
I do n't understand why pressing on either the button add or remove , the form is automatically submitted . I would like to be able to add/remove text inputs dynamically , by pressing on the above mentioned buttons , and my code is working . But as soon as I added the form , I get this weird auto-submit behaviour ... T...
var counter = 3 ; $ ( `` # add '' ) .click ( function ( ) { counter = counter + 1 ; $ ( `` # ingredienti '' ) .append ( ' < input type= '' text '' name= '' '+counter+ ' '' class= '' form-control '' placeholder= '' Inserisci ingrediente '+counter+ ' e quantit & agrave ; '' style= '' margin-bottom : .5em ; '' > ' ) ; $ (...
Why jQuery submits this form ?
JS
I have some text stored in a database , which looks something like below : The text can have many paragraphs and HTML tags.Now , I also have a phrase : What I want to do is search for the phrase in text , and return the complete sentence containing the phrase in strong tag.In the above example , even though the first p...
let text = `` < p > Some people live so much in the future they they lose touch with reality. < /p > < p > They do n't just < strong > lose touch < /strong > with reality , they get obsessed with the future. < /p > '' let phrase = 'lose touch ' They do n't just < strong > lose touch < /strong > with reality , they get ...
NodeJS : Extract a sentence from html text based on a phrase
JS
I have got a map of objects : And I would like to get the key if I know the values ( the values are unique ) , so that I can delete the the entry by its key : I can identify the entry with the given values : But I have no clue how I get the matching key , so that I can delete the entry . Or is there a way to the delete...
Map < String , Transaction > _userIncome = { 'four ' : Transaction ( amount : 450 , date : DateTime.now ( ) , title : 'Einkommen ' , accountType : 'timr ' , notes : 'joa ' , icon : Icon ( Icons.today , ) , id : 'kololdcd ' , repeat : 'always ' ) , 'five ' : Transaction ( amount : 60 , date : DateTime.now ( ) , title : ...
How do I delete the key by knowing its values in flutter ?
JS
I 'm the type of person who loves to do a lot of projects especially if it involves only JavaScript since that is my strong point.I thought of a little fun idea . Writing little pieces of CSS with JavaScript . These CSS pieces could then be used in a Blob or implemented into the webpage some other way.Most of the time ...
var sheet = { `` h1 '' : { `` font-size '' : `` 24px '' , `` color '' : `` blue '' , children : { `` a '' : { `` font-size '' : `` 15px '' } } } , `` a '' : { color : `` red '' } } ; var to = `` '' ; for ( var el in sheet ) { var props = [ ] ; for ( var prop in sheet [ el ] ) { if ( prop ! = `` children '' ) { props.pu...
Creating a property inside of an object that can be continuously used
JS
I was comparing two branches and there is a divergence in code while the + operator , in my opinion it does n't make any difference since it 's push . Is there any difference ? BeforeAfter
if ( numberPattern.test ( val ) ) { var getNumbers = val.match ( numberPattern ) ; for ( i = 0 ; i < getNumbers.length ; i++ ) { valores.push ( getNumbers [ i ] ) } } if ( numberPattern.test ( val ) ) { var getNumbers = val.match ( numberPattern ) ; for ( i = 0 ; i < getNumbers.length ; i++ ) { valores.push ( +getNumbe...
Is there any difference in using the `` + `` operator to push ?
JS
I have an object of users in state , I would like to iterate over it and display a different user every x seconds.This is what I have so far : Essentially a for loop , but I 'm finding it difficult to do in react , what should I do differently ?
class DisplayUser extends Component { constructor ( props ) { super ( props ) ; this.state = { users : [ { name : 'batman ' , age : 25 } , { name : 'spiderman ' , age : 27 } , { name : 'superman ' , age : 26 } ] } ; } tick ( ) { this.setState ( ( prevState ) = > ( { users : prevState.users } ) ) ; } componentDidMount (...
Iterate over object in state every x seconds
JS
I 'm building the obligatory todo list app and running into a weird issue with styling . When I create my li 's I want them to display inline-flex and column , stacked on top of one another . However , they currently display lined up in a row as you create them . I 've played around with this for quite awhile and still...
function addTodo ( ) { let node = document.createElement ( 'li ' ) ; node.setAttribute ( 'class ' , 'list-item ' ) ; let text = document.getElementById ( 'todo-input ' ) .value ; let textnode = document.createTextNode ( text ) ; node.appendChild ( textnode ) ; let deleteButton = document.createElement ( 'button ' ) ; l...
Trying to make my ToDo list < li > tags display as a column but ca n't make it work
JS
Why is it when I haveMy output is Tue , 30 Jun 2015 23:00:00 GMTAndWed , 01 Jul 2015 23:00:00 GMTI 'm clearly missing something here , I want to be able to loop through each days of the month and get a Date ( ) for that dayI do n't understand why if the day is 1 , it says the date is the 30th
var dt = new Date ( 2015 , 6 , 1 ) ; dt.toUTCString ( ) var dt = new Date ( 2015 , 6 , 2 ) ; dt.toUTCString ( )
Explain javascripts Date ( ) functions
JS
If I open a javascript console on a web page and add a variable : Javascript attaches that property to the window object so I can simply access the object by window.abc or directly abcNow , if I try to access something not defined yet through the window objectIt simply returns undefined . So if I dowhy is that an error...
var abc = `` Hello '' ; console.log ( window.abc ) console.log ( abc ) console.log ( window.notdefinedyet ) > undefined console.log ( notdefinedyet )
Understanding how Javascript resolving variables globally
JS
I have the following code.I honestly have no idea whats going on , it seems like an object with an object as a property , but then i dont see why the second example is undefined .
a=7global [ { a } ] =7global [ { a } ] // returns 7b [ { a } ] =7b [ { a } ] // returns undefined
Whats going on here global [ { a } ] =7
JS
The situation is that I am dynamically loading a set of scripts from an API that I then call via eval ( ) . I do n't care which order the scripts are called , but I do n't want any of them to be called at the same time . That is , scripts A , B , and C can be returned in order C , B , A , and I want to begin eval ( C )...
$ .each ( instances , function ( index , instance ) { var apiUrl = `` http : //the-api-url.com/ '' + instance ; $ .getJSON ( apiUrl , function ( data ) { // except I do n't want to eval here as evaluations may overlap eval ( data.script ) ; } ) ; } ) ;
Execute scripts returned from .each ( ) synchronously , but without delay in order of completion
JS
I want to open multiple links using a hotkey on a web page . For this I am using accesskey for hotkey mapping and the following code.The onclick event will not acknowledge when the element is accessed using accesskey ( but tab to select and enter works ) . Is there another DOM event , or method which can accomplish the...
< a href= '' https : //link1 '' onclick= '' window.open ( 'link2 ' ) ; window.open ( 'link3 ' ) ; return true ; '' accesskey= '' 1 '' > Some text < /a >
How can I open multiple links using a hotkey ?
JS
I want to get the content of an element without it being parsed . In this case the results should be & eacute ; however all methods I tried parse the content and return é . How do I get the actual content .
console.log ( 'javascript textContent : '+document.getElementById ( 'test ' ) .textContent ) ; console.log ( 'javascript innerText : '+document.getElementById ( 'test ' ) .innerText ) ; console.log ( 'javascript innerHTML : '+document.getElementById ( 'test ' ) .innerHTML ) ; console.log ( 'jQuery text ( ) : '+ $ ( ' #...
Get unparsed element content
JS
I 'm creating for my education-project a pizza-ordering website . With the help of the stackoverflow-community I 've achieved already a lot - so thank you ! But now I 'm stuck and ca n't find any working solution to my problem.QuestionHow can I change the row color alternating ( white / grey / white / grey ... ) depend...
$ ( document ) .ready ( function ( ) { var check = 0 ; for ( var i =0 ; i < = $ ( `` tr '' ) .length ; i++ ) { $ ( `` tr '' ) .each ( function ( ) { if ( parseInt ( $ ( this ) .find ( `` # bestnr '' ) .text ( ) ) ==check ) { if ( check % 2 == 0 ) { $ ( this ) .css ( `` background-color '' , '' white '' ) ; } else { $ (...
change rows depending on the ordernumber in database
JS
I 'm working on a function that loops over an array ( with arrays ) and then replaces the text on a few divs with the value of index 1 of the nested arrays.But only with these conditions : the nested array needs to have a specific ( string ) value on index 0 ( which is 'categorie 1 ' ) it should only give the value of ...
function displayThemes ( ) { let theme = `` i '' ; for ( let i = 0 ; i < forms.length ; i++ ) { theme = forms [ i ] [ 1 ] ; if ( forms [ i ] [ 0 ] === `` Categorie 1 '' ) document.getElementById ( `` theme '' + i ) .innerHTML = theme ; } } function displayThemes ( ) { let theme = `` i '' ; for ( let i = 0 ; i < forms.l...
How to replace text from divs with only unique values from a specific index of multiple nested arrays
JS
Working on a scroll bar that will be vertical and as we scroll down the brown bit will not fill up but move bit by bit depending on how far we scroll down . So esentially the brown bit will move three times down if we scroll to the bottom . So far I made a scroll bar that fills up but ideally I would like it to have th...
window.onscroll = ( ) = > { var winScroll = document.body.scrollTop || document.documentElement.scrollTop ; var height = document.documentElement.scrollHeight - document.documentElement.clientHeight ; var scrolled = ( winScroll / height ) * 100 ; document.getElementsByClassName ( `` scroll-bar__inner '' ) [ 0 ] .style....
vertical scrollbar moving bit by bit depending on how far you scroll
JS
I have a inheritance chain that goes like Starship - > Capital - > Omega and i would like to to be able to retrieve `` Omega '' from an object of class Omega.Is there a way to retrieve the youngest class that omega is part of , i.e . `` Omega '' or should i just add something like this.type = `` Omega '' to the Omega f...
function Starship ( ) { } function Capital ( ) { Starship.call ( this ) ; } Capital.prototype = Object.create ( Starship.prototype ) ; function Omega ( ) { Capital.call ( this ) ; } Omega.prototype = Object.create ( Capital.prototype ) ; var omega = new Omega ( ) ; omega instanceof Omega // trueomega instanceof Capital...
Javascript class inheritance and name of all inheritances ?
JS
I want to remove duplicates of value , but I want to select the one with the maximum value of length.This is the result i wantThis is the actual result obtainedHow do I write the code to get the result I want ?
let meary = [ ] ; meary.push ( { name : `` aaa '' , value : 90 , length : 3 } ) ; meary.push ( { name : `` bbb '' , value : 90 , length : 5 } ) ; meary.push ( { name : `` ccc '' , value : 80 , length : 3 } ) ; meary.push ( { name : `` ddd '' , value : 0 , length : 4 } ) ; meary.push ( { name : `` eee '' , value : 0 , l...
I want to extract the maximum value among the duplicates
JS
I can ` t get why in my function not changing value of variable . Here my code.This function part of function that fires on ajax success , ajax i call on some select changes . Datain - result of ajax . At first time call this function work ` s fine , but all another fires returns me first time set countarr . All data i...
var count = function ( datain ) { let temparr = [ ] , countobj = { } ; $ .each ( datain , function ( key , val ) { console.log ( temparr ) ; countobj.cost = + $ ( val ) .find ( `` [ name ] '' ) .text ( ) ; console.log ( countobj ) ; temparr.push ( countobj ) ; console.log ( temparr ) ; } ) ; console.log ( temparr ) ; r...
JS not set variable after loop
JS
Forgive me if I 'm wrong , but I thought that by doing this : I create a new instance of the MyObject type.However , if I do this : It returns false . This baffles me , as I thought that this would return true.What am I doing wrong here ? Here 's a fiddle that tests this.I thought that I new the basics of JavaScript , ...
function MyObject ( ) { return { key : 'value ' , hello : function ( ) { console.log ( 'world ' ) ; } } ; } var obj = new MyObject ( ) ; obj instanceof MyObject
JavaScript - instanceof not doing what I expect
JS
This problem occurs only if the state value was actually changed due to the previous update.In the following example , when the button is clicked for the first time , `` setState '' is called with a new value ( of 12 ) , and a component update occurs , which is understandable.When I click the same button for the second...
export default function App ( ) { const [ state , setState ] = useState ( 0 ) ; console.log ( `` Component updated '' ) ; return ( < div className= '' App '' > < h1 > Hello CodeSandbox { state } < /h1 > < button onClick= { ( ) = > setState ( 12 ) } > Button < /button > < /div > ) ; }
Why does calling useState 's setter with the same value subsequently trigger a component update even if the old state equals the new state ?
JS
Is there a more elegant way then this to execute several functions in succession for each item in the array :
type Transform < T > = ( o : T ) = > T ; type Item = { /* properties */ } ; transform ( input , transformers : Transform < Item > [ ] ) { const items : Item [ ] = getItems ( input ) ; return items.map ( item = > { let transformed = item ; tramsformers.forEach ( t = > transformed = t ( transformed ) ) ; return transform...
Map array items through several functions
JS
I have simple angular js controller making a XHR request as belowWhen I wrote this controller using $ scope instead of this the code worked , now the this.php_response property is not containing the data retrieved from the XHR request.I suspect the promise.then # success callback is no longer referencing the controller...
app.controller ( 'MainController ' , [ ' $ http ' , function ( $ http ) { this.php_response = { } ; var promise = $ http.get ( 'process.php ' ) ; promise.then ( function ( success_data ) { // I dont think `` this '' is talking to the controller this anymore ? this.php_response = success_data ; } , function ( error ) { ...
How can I access the `` this '' of an angular js controller , from inside a promise method ?
JS
I want to display a large table to users . To ensure they see all the data before they proceed to the next step I want to hide the `` Next '' button in a way that it will only be visible after the user has scrolled past all the rows.I would also like it to look like the button was hiding behind the table all along , in...
< div id= '' container > < table id= '' table '' class= '' table '' > < ! -- a lot of rows , asynchronously bound with images in some cells -- > < /table > < button id= '' button '' class= '' nextButton '' > next < /button > < /div > .nextButton { position : fixed ; bottom : 0px ; right : 0px ; z-index : -1 ; } .table ...
Button behind table appears when user scrolls past all rows
JS
I 'm hope someone can help me with this.I would like to wrap text around multiple stacked floated elements , however when I am adding a negative margin to the second element the text does not play ball ( see below ) ... Does anyone have a solution that can help me with this ? Thanks in advance ! What I 've done so far ...
< style > .elements { float : left ; padding:10px ; width:50 % ; background : # 039 ; color : # fff ; font-family : Arial , Helvetica , sans-serif ; color : # fff ; padding:50px ; box-sizing : border-box ; margin-right : 20px ; position : relative ; } # element-two { margin-top : -50px ; background : # 900 ; margin-lef...
How can I wrap text around stacked elements ( ie elements with negative margins ) ?
JS
In this code newsData.attributes is retrieved well and I get the table with 3 rows rendered.However , the newsData.is_read values are not retrieved and there is no error message at all , thus , the rows do n't get styling.news is a collection.I wonder , what can be wrong with this ? JSON file that I 'm using for testin...
render : function ( ) { news.fetchMyNews ( ) ; for ( var i = 1 ; i < = news.length ; i++ ) { var newsData = news.get ( i ) ; var newsRow = JST [ `` news/row '' ] ( newsData.attributes ) ; $ ( `` # news_tbody '' ) .append ( newsRow ) ; if ( newsData.is_read == 1 ) { this. $ ( 'tr ' ) .attr ( `` class '' , `` news_read '...
How to specify one attribute of a model inside a collection ?
JS
I have a form with 4 text boxes for IPv4 addy entry that I want to have focus move to the next text field when the user presses the period ascii # 46.The following JS/jQ ( which I basically lifted from : Move Cursor to next text Field pressing Enter ) works for ascii codes for enter ( 13 ) , esc , and even the space ch...
< script language = '' javascript '' type= '' text/javascript '' > function ipfNext ( ) { //alert ( 'FUNC ipfNext ' ) ; $ ( document ) .ready ( function ( ) { $ ( ' # formContent .inputTextIpf ' ) .keydown ( function ( e ) { if ( e.keyCode == 46 ) { $ ( ' : input : eq ( ' + ( $ ( ' : input ' ) .index ( this ) + 1 ) + '...
ca n't focus next input field using ascii 46 ` . ` ( period )
JS
I 'm comparing a variable with an array : $ scope.object.id and $ scope.groepen.id with an if statement after using a for loop . If $ scope.object.id is exactly the same as one of the IDs of $ scope.groepen.id , then it should make that index of $ scope.overlap true . I 'm using another if check to see if anything of $...
for ( var i = 0 ; i < $ scope.groepen.length ; i++ ) { if ( $ scope.object.id === $ scope.groepen [ i ] .id ) { $ scope.overlap [ i ] = true ; if ( $ scope.overlap [ i ] ) { $ scope.bestaand = true ; } else { $ scope.bestaand = false ; } } else { $ scope.overlap [ i ] = false ; } } < div class= '' col-md-3 '' ng-class=...
For looping through array does n't return correct result
JS
I 've been working on a piece of code for a few days now but I somehow ca n't get this to pass the value 1 to my database . Basically what I am trying to achieve is that once the user clicks the button `` collect coins '' it passes the value 1 to my database . Every day at 12 pm the column `` dailyfree '' is reset to 0...
function free ( ) { var str = `` username '' ; var term = `` searched_word '' ; var index = str.indexOf ( term ) ; if ( index ! = -1 ) { var daily = 1 ; $ .ajax ( { url : '' /free ? daily= '' +daily , success : function ( data ) { try { data = JSON.parse ( data ) ; console.log ( data ) ; if ( data.success ) { bootbox.a...
AJAX call on PHP function wo n't make it enter a value to my Database
JS
I am trying to understand MDN 's documentation on .push ( ) and .apply ( ) because I 'm having an issue where I am ending up with an array inside an array in a project . I have set up some experimental code to illustrate my problem . Can anyone explain why the array contents inside foo ( ) print within another array ? ...
var animals = [ ] ; var chickens = 'chickens ' ; var cows = 'cows ' ; animals.push ( cows ) ; animals.push ( chickens ) ; console.log ( animals ) ; // > Array [ `` cows '' , `` chickens '' ] function foo ( ... animals ) { console.log ( animals ) ; // > Array [ [ `` cows '' , `` chickens '' ] ] < -- why is this one insi...
Why do I keep getting an array inside an array when using push ( ) ?
JS
I 'm currently learning JavaScript in school and we are n't using JQuery yet , so I ca n't use that for this assignment . I am dynamically adding rows to a table in JavaScript , based on JSON data . However , I need to make these rows clickable to then call a function.This is what I currently have : How would I go abou...
var table = document.getElementById ( `` destinations '' ) ; for ( var i=0 ; i < myJson.length ; i++ ) { var row = table.insertRow ( i+1 ) ; row.insertCell ( 0 ) .innerHTML = myJson [ i ] [ `` name '' ] ; row.insertCell ( 1 ) .innerHTML = myJson [ i ] [ `` capital '' ] ; row.insertCell ( 2 ) .innerHTML = myJson [ i ] [...
In JavaScript how do I make a dynamically created tablerow clickable without using JQuery ?
JS
I 'm using jQuery to edit XML . Yes , I know that 's probably a bad idea.I came across some very strange behavior ( a bug ? ) when using the xml tag < constructor > . Replacing existing XML with this tag results in the tag being surrounded by 'undefined'.This code works fine for any other tag I try . So far only < cons...
$ ( document ) .ready ( function ( ) { var my_xml = $ .parseXML ( `` < document > < old > original xml < /old > < /document > '' ) ; var new_xml_string = ' < constructor > Foobar < /constructor > ' ; var old_node = $ ( my_xml ) .find ( 'old ' ) ; old_node.replaceWith ( new_xml_string ) ; var my_xml_string = ( new XMLSe...
Why does the tag < constructor > result in 'undefined ' when using jQuery replaceWith ( ) ?
JS
I currently an redirecting to a mobile site based through htaccess as follows : Is there someway to have a full site button on my mobile version that will ignore this rule if clicked ? I do n't want to use javascript to do my redirect and check for full site ... I 'm okay with the idea of php doing it though , but I kn...
RewriteEngine OnRewriteCond % { HTTP_USER_AGENT } `` android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos '' [ NC ] RewriteRule ^ $ http : //m.example.com/ [ L , R=302 ]
Is there a way to have a full site button on a mobile app without javascript ?
JS
Library code ( line 860 in question ) : https : //github.com/jashkenas/underscore/blob/master/underscore.jsif ( remaining < = 0 || remaining > wait ) When is the second half of this true ? Background - first post on SO and pretty new to javascript coding . I 've reimplemented throttle from scratch as an exercise and I ...
_.throttle = function ( func , wait , options ) { var timeout , context , args , result ; var previous = 0 ; if ( ! options ) options = { } ; var later = function ( ) { previous = options.leading === false ? 0 : _.now ( ) ; timeout = null ; result = func.apply ( context , args ) ; if ( ! timeout ) context = args = null...
When is the 'remaining > wait ' conditional statement ever true in underscore.js 's implementation of throttle ?
JS
I have string say `` dd month yyyy '' and I want split to convert to array like [ `` dd '' , `` `` , `` month '' , `` `` , `` yyyy '' ] .What I have so far and this method works . But I 'm looking for Reg expression to do if someone can help ?
function toArray ( format ) { var vDateStr = `` ; var vComponantStr = `` ; var vCurrChar = `` ; var vSeparators = new RegExp ( ' [ \/\\ -. , \ ' '' : ] ' ) ; var vDateFormatArray = new Array ( ) ; for ( var i=0 ; i < pFormatStr.length ; i++ ) { vCurrChar = pFormatStr.charAt ( i ) ; if ( ( vCurrChar.match ( vSeparators ...
Regular expression to split the string but capture sperator
JS
Take a look at this example : https : //jsfiddle.net/qpysmb9t/Whenever text in the contentEditable element becomes bigger that the max-width of the div ( try typing some long text ) , than the left part gets hidden and what 's on the right is shown . This is okay while you type , but on focus out I 'd like to reverse t...
< div tabindex= '' -1 '' contenteditable= '' true '' class= '' name-data '' > This is test < /div > .name-data { max-width:180px ; white-space : nowrap ; overflow-x : hidden ; }
Move overflowed text to beginning when focusing out contentEditable element
JS
I am using bootstrap 4 with CDN.The problem is that I have a boostrap4 carousel ( taken from their official site ) and it works great , but when I run a js code the carousel images disappear.this is the carousel code and it works greatBut when I click on a button in another div , the carousel images disappear and only ...
< link rel= '' stylesheet '' href= '' https : //stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css '' integrity= '' sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z '' crossorigin= '' anonymous '' > < div class='col-7 mx-auto ' > < div id= '' carouselExampleIndicators '' class= '' c...
Bootstrap 4 carousel stopped working when running a js script
JS
I try to animate simple object in canvas and it works at start but after some time it stops to clear rectangles and just continue to fill new rectangles.At least i think it stop clearing maybe is something else . Can anyone help me ? There are no console errors .
var canvas = document.querySelector ( 'canvas ' ) ; canvas.width = window.innerWidth ; canvas.height = window.innerHeight ; var c = canvas.getContext ( '2d ' ) ; var x=100 ; function animate ( ) { requestAnimationFrame ( animate ) ; c.clearRect ( 0,0 , window.innerHeight , window.innerWidth ) ; c.beginPath ( ) ; c.fill...
Why canvas stop clearing rectangle ?
JS
In jQuery is there any difference between andOr are these just alternate syntaxes to get the same thing ?
$ ( '.className > button ' ) $ ( '.className ' ) .children ( 'button ' )
Is there any difference between $ ( '.className > button ' ) and $ ( '.className ' ) .children ( 'button ' ) ?
JS
I 'm adding data points to a bubble graph . However , since the value for r is very small I can barely see the points on the graph . I tried to use the radius property to expand the radius , but it seems to be overwritten by the r data property . How can I increase the radius for each bubble ? For example , how can I s...
this.managers.forEach ( manager = > { const newDataPoint = { label : [ manager.SecurityName ] , backgroundColor : this.getRandomRGB ( ) , borderColor : this.getRandomRGB ( ) , data : [ { x : +manager [ this.selectedX ] , y : +manager [ this.selectedY ] , r : +manager [ this.selectedR ] } ] , radius : ( +manager [ this....
Change size of bubble radius without changing r value
JS
I am looking at some code , and I see that it is written as shown below . It does n't make sense to me . Is it wrong ? Why is it written like that ? Also , should n't the use strict ; go at the very top , outside of the code ?
( function ( ) { 'use strict ' ; angular.module ( 'itemList ' , [ ] ) .component ( 'itemList ' , { templateUrl : 'item-list/item-list.component.html ' , controller : [ 'Item ' , ItemController ] } ) ; function ItemController ( Item ) { //code } } ( ) ) ;
Is it wrong to define controller in angular wrapped in a function ?
JS
I often see something like this in other people 's scripts : However , the following shorter notation works fine as well : Are these two constructs fully equivalent ? Are there engines ( browsers ) that treat them differently ?
bar = Array.prototype.slice.call ( whatever , 1 ) bar = [ ] .slice.call ( whatever , 1 )
Is explicit `` .prototype '' really needed ?
JS
I am working on a JavaScript library ( repository here ) and it includes both the source code inside the directory lib/ and some demos/examples inside the directory demos/ . Both some of the demos as well as the entire source code of the library must go through Webpack as they have to go through Babel ( because I 'm us...
import path from 'path ' ; export default { entry : { Sprite : `` ./lib/Sprite.js '' , SpriteList : `` ./lib/SpriteList.js '' , Game : `` ./lib/Game.js '' , HelicopterDemo : `` ./demos/helicopter_game/PlayState.js '' , CircleExample : `` ./demos/circle_example/PlayState.js '' } , output : { path : __dirname , filename ...
Organization for source code and demos
JS
Alright , first time posting here . I have been looking at posts regarding this issue for days now and I ca n't find a fix.I have a matrix of images ( basically arranged spheres ) with unique id 's . I want to add different functionalities to said spheres . So I proceed to add event listeners . All good so far . After ...
for ( let i = 0 ; i < 11 ; i++ ) { for ( let j = 0 ; j < 11 ; j++ ) { if ( ( i > 1 & & i < 9 & & j > 1 & & j < 9 ) & & checkCorners ( i , j ) === true ) { let ball = document.getElementById ( i.toString ( ) + j.toString ( ) ) ; ball.addEventListener ( 'click ' , removeBall ( i , j ) ) ; } } } var removeBall = function ...
Adding and removing event listeners with argument bearing functions
JS
When the given cookie does not exist , the result must be null or undefined , but in this case favouritescook does n't exist but the script thinks it does.The result must be `` OK Detect '' for null or undefined , but the result is `` BAD no detect result '' . Why is n't this working ? I have tried this in different br...
< script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js '' > < /script > < script src= '' https : //cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js '' > < /script > < script > actcookies=jQuery.cookie ( `` favouritescook '' ) ; function fav ( id ) { if ( actcookies=='unde...
Jquery cookie not detect no exist
JS
The goal is to hide the # boxar when the toggle is active and return the `` # boxar '' when `` toggle is closed . The code works fine until I close the toggle ( the `` # boxar '' disappears ) but when I close the toggle , they wo n't return . Anyone who knows how to fix this ?
$ ( document ) .ready ( function ( ) { $ ( ' # toggle ' ) .click ( function ( ) { $ ( '.boxar ' ) .hide ( ) ; $ ( ' # '+this.rel+ '' ) .show ( ) ; return false ; } ) ; } ) ;
`` Return '' content when closing toggle
JS
I have a basic model : Nothing special there , however I 've noticed values in the config option are remembered between instances . For example : So , why in test2 , is the screen_name being preserved from test1 ? How can I prevent this from happening ?
myTestModel = Backbone.Model.extend ( { defaults : { title : 'My Title ' , config : { } , active : 1 , } } ) var test1 = new myTestModel ( ) ; test1.set ( 'title ' , ' A New Title ' ) ; test1.get ( 'config ' ) .screen_name = 'Joe ' ; alert ( test1.get ( 'title ' ) ) ; // ' A New Title ' , expected.alert ( test1.get ( '...
Backbone `` remembering '' values in properties
JS
I have a relatively simple issue I 'm trying to resolve and ca n't seem to find anything about it.I am working on existing product , after an error modal is closed I need to focus on a given form field , which at this point I will have stored in a variable.Currently this works : I 've simplified the variable names . No...
$ ( `` input [ field='number ' ] '' ) .focus ( ) ; $ ( `` input [ field=myField ] '' ) .focus ( ) ; $ ( `` input [ field='myField ' ] '' ) .focus ( ) ;
Focus on a form field with a variable
JS
I have searched and dug and found questions with answers that I thought were going to help , but never did . I just can not get this to work . I have already asked a question regarding this issue and I was directed elsewhere and still no dice .
< br > Make : < br > < select id= '' make '' name= '' make '' required > < option value= '' default '' > Select make ... < /option > < option class= '' alfaRomeo '' value= '' alfaRomeo '' > Alfa Romeo < /option > < option class= '' abarth '' value= '' abarth '' > Abarth < /option > < option class= '' astonMartin '' val...
How do I make this dropdown category correspond with my other dropdown category ?
JS
The issue with the converting from HTML to DOC is with the input field . Is it possible to extract to DOC only value from input field but not the whole element directly from browser ? Example HTML : Javascript code that I 'm using : Exported doc looks like this , but I would love to export it without input field ( just...
< html > < head > < title > How to Export HTML to Word Document with JavaScript < /title > < /head > < body > < div class= '' source-html-outer '' > < div id= '' source-html '' > < h1 > < center > Artificial Intelligence < /center > < /h1 > < h2 > Overview < /h2 > < p > Artificial Intelligence ( AI ) is an emerging tec...
Convert HTML to Word DOC where I have input field
JS
tl ; dr : In the LoginForm , this.props is undefined despite my passing in actions in mapDispatchToProps.I 've set breakpoints in the connect function , and the action is making it into the connect function , but for whatever reason , in the handleSubmit function , this.props is undefined.I 'm stumped.I have a separate...
import React from 'react ' ; import { connect } from 'react-redux ' ; import { loginSubmit , loginUpdateField } from '../../redux/actions/login.actions ' ; import { TextInput } from '../../stories/TextInput ' ; import { Button } from '../../stories/Button ' ; export class LoginForm extends React.Component { // eslint-d...
Why is this.props undefined when I 'm passing in actions to mapDispatchToProps ?
JS
I have an array of strings : Order of an array items is not always the same.I want to sort that array so it goes like this : Goalkeeper , Full back , Centre back , Midfielder , Winger , Striker.I 'm thinking about enums but I do n't know how to use them in this situation .
var players = [ { Name : player1name , Surname : player1surname , Position : `` Centre back '' } , { Name : player2name , Surname : player2surname , Position : `` Striker '' } , { Name : player3name , Surname : player3surname , Position : `` Full back '' } , { Name : player4name , Surname : player4surname , Position : ...
Javascript - sort array of strings in a custom way
JS
I have this literal notation object ( took out the irrelevant parts ) : I have tried calling it with : None of these have worked . How do I go about calling this function ? If i place the function outside of the literal notation object than I can call it just fine with :
var work = { `` display '' : function displayWork ( ) { for ( i in work.jobs ) { $ ( ' # workExperience ' ) .append ( HTMLworkStart ) ; var formattedEmployer = HTMLworkEmployer.replace ( ' % data % ' , work.jobs [ i ] .employer ) ; var formattedTitle = HTMLworkTitle.replace ( ' % data % ' , work.jobs [ i ] .title ) ; v...
Calling a variable stored in a literal notation object
JS
Code : Results : Calling ns result : Object { foo2 : `` bar2 '' } IIFE returns : Object { foo : `` bar1 '' , foo3 : `` bar3 '' } 1 . Do I understand it correctly ? ns is a new , private object inside IIFE which is then returned this.ns belongs to window.ns and expands it 2 . Why this keyword in this.ns ? Since IIFE is ...
; ( function ( ns , undefined ) { ns = { foo1 : `` bar1 '' } this.ns = { foo2 : `` bar2 '' } ; ns.foo3 = `` bar3 '' ; return ns ; } ) ( window.ns = window.ns || { } ) ;
Extending namespaced module from within
JS
I have the following : When visiting / then Home is correctly loaded . When visiting a non-existing route then Home is loaded again but when visiting /about Home is loaded instead of AboutUs.What 's weird is that if I move AboutUs component to be loaded when visiting / instead of loading Home then AboutUs works well
import React , { Component } from 'react ' ; import { Switch , Route , Redirect } from 'react-router-dom ' ; import Header from './layout/Header ' ; import Home from '../pages/Home ' ; import AboutUs from '../pages/Aboutus'import { Layout } from 'antd ' ; class Main extends Component { render ( ) { return ( < Layout cl...
React Router not routing correctly
JS
I got a form with some text inputs and one select options , and i want to alert the input id when user is preforming key up event or change selection in the select options . whats the best way to do it ? right now i am writing a function for each one : ( my bad code so far : this my form :
$ ( `` # target '' ) .keyup ( function ( ) { alert ( this.id ) ; } ) ; < form > < div class= '' col-md-6 '' > < div class= '' form-group '' > < input type= '' text '' class= '' form-control input-lg '' name= '' FirstName '' id= '' FirstName '' placeholder= '' First Name '' maxlength= '' 45 '' required= '' '' > < /div >...
How to get the specific id of an input which the user did key up on it
JS
Is it pointless to use hasOwnProperty in the looping because object will always have properties ? For example :
const fruits = { apple : 28 , orange : 17 , pear : 54 , } for ( let property in fruits ) { if ( fruits.hasOwnProperty ( property ) ) { console.log ( fruits [ property ] ) ; } }
Looping through object with hasOwnProperty check ?
JS
I 've just run into something that really surprises me . Consider the following four functions : and let 's create objects ( via new ) from all of them : This is the output : First three seem to indicate that it does n't matter what the function returns , that JS only cares about what each function does with this ( whi...
function A ( ) { this.q = 1 ; } function B ( ) { this.q = 1 ; return this ; } function C ( ) { this.q = 1 ; return 42 ; } function D ( ) { this.q = 1 ; return { } ; } console.log ( ' a ' , new A ( ) ) ; console.log ( ' b ' , new B ( ) ) ; console.log ( ' c ' , new C ( ) ) ; console.log ( 'd ' , new D ( ) ) ; a A { q : ...
Strange behaviour of Javascript ` new ` from ` function `
JS
I 'm just learning some java . I am currently learning if , else statements.In the game I am creating , the user picks a number between 0 and 10 and puts it into an input box . If correct , the image on screen changes to one picture , if incorrect , it switches to a different picture . However , I can not seem to get t...
< div id= '' top '' > < h1 > Pie in the Face < /h1 > < p > Guess how many fingers I 'm holding up between 0 and 10 . < br / > If you guess correctly , I get a pie in the face . < br / > If you guess wrong , you get a pie in the face. < /p > < input id= '' answer '' / > < button id= '' myButton '' > Submit < /button > <...
Having Trouble Switching Images
JS
I have the following loop : where f and g are defined as follows : Also sleep is defined as follows : My intention is to have SOME_REQUEST_F awaited every one second , and SOME_REQUEST_G awaited every five seconds , hence wrapping them in f and g. However , currently g is blocking the re-awaiting of f within the loop.H...
while ( true ) { await f ( ) ; await g ( ) ; } async function f ( ) { await Promise.all ( [ SOME_REQUEST_F , sleep ( 1000 ) ] ) } async function g ( ) { await Promise.all ( [ SOME_REQUEST_G , sleep ( 5000 ) ] ) } function sleep ( ms ) { return new Promise ( resolve = > setTimeout ( resolve , ms ) ) ; }
How to call two async functions every ` n ` and ` m ` seconds within a ` while ( true ) ` loop ?
JS
I am trying to add a class on the row the user is clicking on . To do that , I use the responsive-display event.But row is not a jQuery object so addClass ( ) does not work . How should I do ?
$ ( function ( ) { $ ( ' # people-waiting-send-up ' ) .DataTable ( ) .on ( 'responsive-display ' , function ( e , datatable , row , showHide , update ) { row.addClass ( 'opened ' ) } ) ; } ) ;
How to add a class on a row on responsive-display ?
JS
Consider this : Even if you choose the same file and the filePicker value does n't change , you 'll see the alert box in Firefox . Any solutions ?
< input type= '' file '' id= '' filePicker '' > < script > document.getElementById ( 'filePicker ' ) .onchange = function ( ) { alert ( 'Hi ! ' ) ; } ; < /script >
Firefox fires on choose , not on change
JS
This is my function userNameEditorI want to catch kendoComboBox value go controller and come back with user name contains value just give me way to take value PLEASE ! ! ! ! This is my grid column area
function userNameEditor ( container , options ) { $ ( ' < input required data-bind= '' value : ' + options.field + ' '' / > ' ) .appendTo ( container ) .kendoComboBox ( { dataTextField : `` UserName '' , dataValueField : `` UserId '' , filter : `` contains '' , minLength : 3 , //_readMethod : '../Warehouse/SearchUser '...
Inline Grid kendoComboBox get value in javascript
JS
I have about 1000 images and textareas with the same class name and a custom attribute . The classes names are emoticon and emoticonlist respectively . The custom attributes are emo-tag and emo-ascii respectively . Each image has its partner ( a textarea ) with the exact same content in its custom attribute.Example : w...
emo-tag = `` f-x '' // for imagesemo-ascii = `` f-x '' // for textareas $ ( function ( ) { var json = [ ] ; $ ( 'img ' ) .each ( function ( ) { var emoimg = $ ( this ) .attr ( `` src '' ) ; var emoalt = $ ( this ) .attr ( `` alt '' ) ; var emotag = $ ( this ) .attr ( `` emo-tag '' ) ; //Does not this supposed to captur...
Populating array with items from different HTML attributes
JS
According to the section 3.8.3 in the book Javascript the Definitive Guide 6th edition : To convert an object to a string , JavaScript takes these steps : • If the object has a toString ( ) method , JavaScript calls it . If it returns a primitive value , JavaScript converts that value to a string ( if it is not already...
var obj = { toString : function ( ) { console.log ( 'toStirng ... ' ) ; return 90 ; } , valueOf : function ( ) { console.log ( 'valueOf ... ' ) ; return 80 ; } } console.log ( obj + `` ) ; toString ... 90 valueOf ... 80
Javascript the Definitive Guide : the confusion of steps of converting object to a string
JS
I encountered this obscure syntax : How does it work ?
const a = { } const c = [ 1,2,3 ] for ( a.b of c ) { } assert ( a.b === 3 )
What does property access in a for-of loop do , like ` for ( a.b of c ) ` ?
JS
I have a form where I need such facility where user input some data in textfield and hits enter that time using jquery it should create new controls like new textfield , dropdown menu , textfield . and it works also , but it has a bug like when user input another data and hits enter that time value of previous controls...
< script type= '' text/javascript '' > function addMbo ( value ) { var div = document.getElementById ( 'mboTable ' ) ; var keycode = ( event.keyCode ? event.keyCode : event.which ) ; if ( keycode == '13 ' ) { event.preventDefault ( ) ; var divName = document.getElementById ( 'mboName ' ) ; var divState = document.getEl...
On particular javascript function call HTML control 's value changes to its default value
JS
I am looping over a group of elements with the same class . Now when an element is clicked I need it to get a class that makes it active and adds some css to it . This works but it stays forever , so if I click 4 elements I have 4 active elements.I 'm trying to remove the class from all sibling elements when 1 is click...
$ ( '.klantenblokje ' ) .each ( function ( i , obj ) { $ ( this ) .on ( `` click '' , function ( e ) { e.preventDefault ( ) ; var id = $ ( this ) .attr ( 'id ' ) ; $ ( this ) .addClass ( 'activeblok ' ) ; $ ( this ) .siblings ( ) .removeClass ( 'activeblok ' ) ; } ) ; } ) ; $ ( '.klantenblokje ' ) .each ( function ( i ...
How to remove a class of all sibling elements when an element is clicked inside a jquery each loop