lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I 'm working on my new blog , for now the server side is NodeJS ( using expressjs ) , I host the server on my computer.For rapid development I 'm using GulpJS.Before I explain the weird thing . Let me say that both ports ( 3000 and 80 are open ) .Gulp version : 3.9.0NodeJS version : 0.10.35Browser-sync : 2.7.12This is ...
var express = require ( 'express ' ) ; var app = express ( ) ; app.use ( express.static ( 'public ' ) ) ; app.set ( 'base ' , '/public ' ) ; app.get ( '/ ' , function ( req , res ) { res.sendfile ( 'index.html ' ) ; } ) ; var server = app.listen ( 80 , function ( ) { var host = server.address ( ) .address ; var port = ...
Reflected client actions from a different computer
JS
I want to : Is it possible ?
// Display loader spinner// Check if ID or Class exist in HTML Page// If ID or Class are found , load a specific css file// Display HTML PAGE
How can I load a specific css file in a specific case with JavaScript ?
JS
I have a Javascript object defined as follows : I push to array scenario with : However I get 0 when : So of course I can not loop through the array content . If I do : I see the array content within Chrome plus the correct array length . I have similar code that defines and works with arrays , but outside of an object...
var active = { waypoints : [ ] , scenario : [ ] } var myScenario = { id : terrainId , text : text } ; active.scenario.push ( myScenario ) ; console.log ( active.scenario.length ) ; console.log ( active.scenario )
Javascript length of array in object
JS
I want to insert multiple data ( PHP CodeIgniter ) using array . but I still find an error . The error is array is not clearwhen I var_dump show the result likethe result is should be likewhat should I do ? How if like this ? but show an error
function insert ( ) { $ hitung=count ( $ _POST [ 'pembicara ' ] ) ; $ pengisi=implode ( ' , ' , $ _POST [ 'pembicara ' ] ) ; $ materi=implode ( ' , ' , $ _POST [ 'materi ' ] ) ; $ alasan=implode ( ' , ' , $ _POST [ 'alasan ' ] ) ; $ datapembicara = array ( 'id_kegiatan ' = > $ x , 'nama_pembicara ' = > $ pengisi , 'mat...
PHP into database with dynamic form with javascript ( codeigniter )
JS
I am using Angular 4 for my web template.HTML is generated once the HTTP get method is called inside the constructor , the response of which creates the HTML.The above works fine.I am also using jQuery with Angular and trying to initialize a function on this page.I have tried calling the above code inside various lifec...
$ ( function ( ) { Books.init ( ) ; } ) ;
How can I call a function in jQuery once HTML is completely rendered dynamically in Angular 4 ?
JS
Here I found a pattern of javascript module enabling private members of object . If I got it right , it can be written this way : But there is more effective way : Is there any difference between those two ? Are there any other possibilities to implement private members ? This is the result from Chrome debugger :
var myObject1 = ( function ( ) { var privateMember = 42 ; return { publicMember : function ( ) { return privateMember ; } } } ) ( ) ; var myObject2 = new function ( ) { var privateMember = 42 ; this.publicMember = function ( ) { return privateMember ; } }
Technical differences in creating object with private member
JS
Need to capitalize the first letter of each word in a sentence , my regex expression however is also capitalizing the 'm ' in I 'm . The full expression is this : The problem here ( I think ) is that \b\w will grab the first letter after a word boundary . I 'm assuming that single quotes denote a word boundary therefor...
/ ( ? : ^\w| [ A-Z ] |\b\w ) /g
Capitalizing first letter of each word , \b\w also applies to I 'm
JS
I am in the following situation : I have to check if the object parameter passed to a function is valid : Exmaple : Is there a better way to make this kind of check ?
function ( opt ) { if ( opt & & opt.key & & opt.key2 ) { // make something } }
I am looking for a smart way to check the object parameter passed to a function
JS
LikeIf i want to get all id 's starting with 'box_ ' how can i do it something like this..Unfortunately wrapping the div 's wo n't work because it will get all the other divs in side and between the box divs.I guess i can give them all another class and reference it like that , but just wondering if there 's something ...
< div id= '' box_1 '' > < div id= '' box_2 '' > < div id= '' box_3 '' > $ ( `` # box_ '' + anything )
Is it possible to get a selector using indexOf
JS
I feel this should be answered somewhere in the internet but I failed to find it , maybe because I 'm not searching the correct terms but this is the problem : I have the following function : I was getting errors in succesFunction ( data , k , Parameters ) because ' k ' was always evaluated with the latest value . What...
function ParentFunction ( DataBase , Parameters ) { for ( k = 0 ; k < DataBase.length ; k++ ) { var CalendarURL = `` https : //www.google.com/calendar/feeds/ '' + DataBase.cid ; $ .ajax ( { url : CalendarURL , dataType : 'json ' , timeout : 3000 , success : function ( data ) { succesFunction ( data , k , Parameters ) ;...
Correct way to pass a variable argument in a callback in JavaScript ?
JS
See the code below : I want to know why 2..toString ( ) can run without errors and what happens when it runs ? Can somebody explain it ?
2.toString ( ) ; // error2..toString ( ) ; // `` 2 '' 2 ... toString ( ) ; // error
Javascript Function toString
JS
I 'm trying to build a simple CMS where users can write anything in contenteditable div . When they 're saving their work I want to remove specific characters from the text they putted i.e . : The text is : I know how to remove the comma with jquery .text ( ) , but it just gives me a plain text without HTML tags . The ...
< ul > < li > This is the text inserted by < b > user < /b > and styled by him - there should be no comma at the end of a < b > < i > < u > LI element , < /u > < /i > < /b > < /li > < /ul >
Jquery - removing a character from HTML but leaving html tags unchanged
JS
I 'm new with knockout.js and I do n't know how to do multiple mapping with my object.That 's my data from the server : I do a first mapping on the whole object and ko.computed some datas : After executing this , I get what I want for the first part : But now , I want to do the same thing with the contract array inside...
var persons = { 'value ' : [ { `` id '' : `` 1 '' , `` civility '' : `` Mr. '' , `` firstname '' : `` john '' , `` lastname '' : `` doe '' , `` phone '' : `` 00 00 00 00 00 '' , `` email '' : `` email @ email.com '' , `` contract '' : [ { `` id '' : `` 1 '' , `` gamme '' : `` Gamme 1 '' , `` formula '' : `` Formula 1 '...
knockout.js Multiple mapping in nested objects
JS
I have a bivariate dataset with 100 observations . I used hexagon binning and ended up with 26 hexagon bins . In order to save the rows of the 100 observations that are in each of the 26 hexagon bins , I used the base : :attr function in R. In the code below , this is done at : I am trying to create an interactive R Pl...
attr ( hexdf , `` cID '' ) < - h @ cID library ( plotly ) library ( data.table ) library ( GGally ) library ( hexbin ) library ( htmlwidgets ) set.seed ( 1 ) bindata < - data.frame ( ID = paste0 ( `` ID '' ,1:100 ) , A=rnorm ( 100 ) , B=rnorm ( 100 ) ) bindata $ ID < - as.character ( bindata $ ID ) x = bindata [ , c ( ...
Retrieving R object attributes in JavaScript
JS
I have a jQuery statement like this ; I want to change this into a single statement and I wrote ; But ab is not hiding . How can I combine the 3 hide ( ) statements into one ?
var current = $ ( this ) ; current.hide ( ) ; current.siblings ( '.ab ' ) .hide ( ) ; current.siblings ( '.cd ' ) .hide ( ) ; $ ( current , current.siblings ( '.ab ' ) , current.siblings ( '.cd ' ) ) .hide ( ) ;
How can I combine these jQuery statements ?
JS
This is a strange issue I 'm facing . When I pass some big numbers to JS functions ( custom or built-in ) the value is automatically getting incremented by 1 . For example , see this : in the alert I 'm seeing 10466511635124472 , instead of 10466511635124471 . Can someone explain this behavior ? I have checked this in ...
< ! DOCTYPE html > < html > < body > < p > Click the button to display an alert box. < /p > < button onclick= '' myFunction ( ) '' > Try it < /button > < script > function myFunction ( ) { alert ( 10466511635124471 ) ; } < /script > < /body > < /html >
Issue with some big numbers in Java Script
JS
I want to do event delegation and capture all events happening on a DOM object by an event handler bound to the entire document . Is there any difference between binding the events to window as in : and window.document as in the following ? event is some kind of event like 'click ' , 'mouseover ' , etc .
window.addEventListener ( event , function ( e ) { var obj = e.target ; ... // if ` obj ` is a certain kind of object , then do something } , false ) ; window.document.addEventListener ( event , function ( e ) { var obj = e.target ; ... // if ` obj ` is a certain kind of object , then do something } , false ) ;
Event delegation and window versus window.document
JS
I 'm trying to push a value to an array , but this adds the value to both arrays a and b . How can I make sure that the b array is not modified ?
var a= [ [ 1 ] ] ; var b= [ 2 ] ; document.getElementById ( `` 1 '' ) .innerHTML= '' a [ 1 ] `` +a [ 1 ] ; document.getElementById ( `` 2 '' ) .innerHTML= '' b `` +b ; a.push ( b ) ; document.getElementById ( `` 3 '' ) .innerHTML= '' a [ 1 ] `` +a [ 1 ] ; document.getElementById ( `` 4 '' ) .innerHTML= '' b `` +b ; a [...
Why does `` a.push ( b ) '' change `` b '' in my example code ?
JS
I 'm having a trouble to get an array with numbers from 1 to 16 randomly without repetition.I made num array to put numbers from createNum function.The createNum function has a for loop which gets numbers from 1 to 16 until if statement push 16 numbers into num array.At the end , I run createNum ( ) and display numbers...
let num = [ ] ; function createNum ( ) { for ( i = 0 ; i < = 15 ; ) { let numGen = Math.floor ( Math.random ( ) * 15 ) + 1 ; if ( ! num.includes ( numGen ) ) { num.push ( numGen ) ; i++ ; } ; } ; } console.log ( createNum ( ) ) ; document.getElementById ( `` selectedNumbersShownHere '' ) .innerHTML = num ; console.log ...
Simple for loop does not seem work properly
JS
I 've came into a problem where I have to re-type / re-define repeating types in my store / view / components files i.e . Think a view that takes in some store value and has a function that alters that value and this function is passed down to a component.There is a lot of type re-usability happening here and I went on...
// @ flowimport React , { Component } import OtherComponent from `` ./OtherComponent '' export type MyComponentProps = { something : string } export type MyComponentState = { something2 : boolean } export type MyComponentActions = { check : ( something2 : $ PropertyType < MyComponentState , 'something2 ' > , something ...
Structuring react project with flow type for best type reusability
JS
I am having trouble getting the errorCount property to increase during code execution . The problem I am having is occurring inside of the $ .ajax request , more specifically the addError ( ) method . If I use the following code below to check the current count of errorCount it always returns 0 even though I have manua...
var boom = new test ( settings , formData , search ) ; console.log ( boom.errorCount ) ; boom.queueCalls ( settings ) ; console.log ( boom ) ; console.log ( boom.errorCount ) ; function test ( a , b , c ) { this.settings = a ; this.formData = b ; this.search = c ; this.errorCount = 0 ; } test.prototype = { constructor ...
Javascript object counter not incrementing as expected
JS
Here is an array example I have : I want this result : It means , separate from this ' > 'No duplicateThis is an example of where I 'm at but it just removes the arrow ' > ' jsfiddle
var array= [ 'business > management ' , 'News > Entertainment News ' , 'business > Entrepreneurship ' ] ; [ 'business ' , 'management ' , 'News ' , 'Entertainment News ' , 'Entrepreneurship ' ]
Modify and manipulate JavaScript array
JS
So far I 've got this code http : //jsfiddle.net/Nq79H/1/but I want to fadeout the image in order to leave only the text visible.Do I need to change the javascript or write a new css div ?
$ ( '.text ' ) .hide ( ) .removeClass ( 'text ' ) .addClass ( 'text-js ' ) ; $ ( '.thumb ' ) .hover ( function ( ) { $ ( this ) .find ( '.text-js ' ) .fadeToggle ( ) ; } ) ;
Opacity on a div hover
JS
I have a react component that maps through an array.Each array item has an optional ID type.If I have this ID , I will render an element , otherwise nothing.This element has an onClick that calls a function accepts the ID as param.Even though I check if I have the ID , TypeScript still complains that the ID might be un...
// fake bindingsdeclare namespace React { function createElement ( ) : any ; } // This type has an optional proptype SampleType = { id ? : string ; name : string ; } const sampleArray : SampleType [ ] = [ { id : 'test ' , name : 'Adrian ' } , { name : 'Florescu ' } ] function sampleFunction ( id : string ) { console.lo...
TypeScript/JSX Type Assertion works only outside JSX
JS
I could n't find an exact match on my issue , though many javascript scoping questions do exist . Here is my current code for the question.When I run this , I am alerted with `` blank '' and then `` one '' as expected . However , if I uncomment that one line , so it looks like this.I am alerted with `` blank '' and the...
var my_var = `` blank '' ; var MyFunc = function ( ) { my_var = `` one '' ; //var my_var = `` two '' ; } alert ( my_var ) ; MyFunc ( ) ; alert ( my_var ) ; var my_var = `` blank '' ; var MyFunc = function ( ) { my_var = `` one '' ; var my_var = `` two '' ; } alert ( my_var ) ; MyFunc ( ) ; alert ( my_var ) ;
Javascript Scoping Confusion
JS
I have structure like : appscriptslibsjquery.jsbootstrap.jsmoment.jsapp.jsvendor.jscommon.jsapp.config.jsmain.js # require configNote vendor.js is just a file that includes all files under libs . Ex//vendor.jsdefine ( [ 'jquery ' , 'bootstrap ' , 'moment ' ] , function ( ) { } ) ; Just to list out the dependencies : ap...
module.exports = function ( grunt ) { 'use strict ' ; var config = { dist : { options : { appDir : 'app/ ' , baseUrl : './scripts ' , mainConfigFile : 'app/scripts/main.js ' , dir : 'dist/scripts/ ' , modules : [ { name : 'vendor ' } , { name : 'app ' , exclude : [ 'vendor ' ] } ] } } } ; grunt.config ( 'requirejs ' , ...
Grunt require fails to create multiple modules as expected
JS
I 'm using typeahead.js to create a simple dropdown list . The user should be able to use the down key to scroll through suggestions , and be able to use the mouse to select a suggestion . The suggestions should be appropriately highlighted in either of these scenarios.The problem I 'm having is achieving the above wit...
.tt-suggestion : hover { color : # f0f0f0 ; background-color : # 0097cf ; } .tt-cursor { color : # f0f0f0 ; background-color : # 0097cf ; }
CSS : Target an element on hover OR focus , but not both
JS
I have seen a few similar to what I am looking for but not exactly the same.So what I am trying to do is move elements from within one parent div to another but only once the user has scrolled a certain amount down the page . So once the user has reached a point on the page the elements will then move to another and th...
$ ( document ) .scroll ( function ( ) { var y = $ ( this ) .scrollTop ( ) ; if ( y > 600 ) { $ ( ' # Top ' ) .fadeIn ( ) ; } else { $ ( ' # Top ' ) .fadeOut ( ) ; } } ) ; # Top { display : none ; position : fixed ; top : 0 ; left : 0 ; width : 100 % ; border-bottom : 2px solid # f2f2f2 ; border-radius : 0 ; background-...
Move Div element from one to another when page scrolled
JS
An AngularJS app needs to re-use multiple custom objects . I am concerned about creating cluttered , redundant code that is hard to maintain , so I moved re-usable code to a service that can be concisely injected in the controller for each view and then called directly from each html view without cluttering the control...
angular.module ( 'someclass ' , [ 'ngCookies ' ] ) .service ( 'someclass ' , [ ' $ rootScope ' , ' $ http ' , ' $ cookies ' , function ( $ rootScope , $ http , $ cookies ) { this.prop1 = $ cookies.get ( 'test1 ' ) ; this.prop2 = 'nothing ' ; this.resultphone = { } ; this.method1 = function ( isValid , resultphone ) { i...
Why ca n't AngularJS view send data to this re-usable service ?
JS
I have a line in the form of an array of coordinate points : The points which make up the line are at varying distances from one another.My goal is to make a function which takes this line and split it up into evenly separated distances.All I 'm looking for is the terminology for this process ... Interpolation ? becaus...
[ { x1 , y1 } , [ x2 , y2 ] , ect ... ]
Is there a name for `` Breaking up a line at regular intervals '' ?
JS
I noticed that the async keyword can be assigned any value whatsoever and even used as a normal variable : Yet , even then it continues to operate as before : Even await is doing the same thing : What is going on here ? Why are the keywords usable as a variables ?
let async = `` world '' ; console.log ( async ) console.log ( `` Hello `` + async ) let async = `` world '' ; async function foo ( input ) { return input ; } let barPromise = foo ( `` bar '' ) ; console.log ( `` bar promise is : '' , typeof barPromise ) ; console.log ( `` bar promise also has a .then : '' , typeof barP...
Why can the ` async ` and ` await ` keywords be assigned to ?
JS
I have some element in body . I want to know their indexing like div indexing should be 1 and span its indexing should be 2 . How to start find
$ ( function ( ) { var id= document.getElementsByTagName ( '* ' ) ; for ( i=0 ; i < id.length ; i++ ) { alert ( id [ i ] ) } } ) < body > < div > < /div > < span > < /span > < p > < /p > < strong > < /strong > < /body >
How to get element indexing using javascript
JS
I always wondered why js compressors do n't do this . Let 's say I have a minified script like this : Why does n't it compile to something like this : Meaning changing every occurrence of a .property with a [ minified key ] and pass a string and arg receiver to the iife ( basically what I did above with the .length ) I...
( function ( $ ) { var a= $ ( `` a '' ) ; 1 < a.length & & 10 > a.length ? alert ( a.length ) : alert ( $ ( `` p '' ) .length ) } ) ( jQuery ) ; ( function ( $ , L ) { var a= $ ( `` a '' ) ; 1 < a [ L ] & & 10 > a [ L ] ? alert ( a [ L ] ) : alert ( $ ( `` p '' ) [ L ] ) } ) ( jQuery , 'length ' ) ; ( function ( $ , L ...
Why do n't js compressors do this ?
JS
I am trying an animation on the two divs on button click . Here is the demo i have created js fiddle . what i want is when the user will click on the button the right div will slide to right ( it will hide ) . and the width of left div will become 100 % .on second time when user will click the right div will visible fr...
< div class= '' col-md-12 '' > < div id= '' tags-left '' class= '' col-md-6 '' > div left < /div > < /div > < div id= '' tag-div '' class= '' col-md-6 '' > div right < /div > < /div > < div class= '' col-md-12 '' > < div class= '' btn-main '' > < input id= '' show-tag '' type= '' button '' class= '' save-btn '' value= ...
animation is not working as expected
JS
If you run this code in Firefox and Chrome , it will output a different converted string.In Firefox it will return a value of `` 0.4fxcm49g2j8 '' In Chrome or Node 4+ ( likely a V8 difference ) , I get a value of `` 0.4fxcm49g2j91m31w5nq6ldte29 '' .In IE and Edge it is `` 0.4fxcm49g2j91 '' ( thanks @ JaromandaX ) Anyon...
( 0.1234 ) .toString ( 36 )
Why does using toString ( ) on a float give different results in Firefox vs Chrome vs IE ?
JS
Is the following code valid ? It seems that many javascript minifiers ( including jsmin at http : //jscompress.com/ ) consider the `` // '' on the second line to be the start of a comment . I assume it 's a bug in the `` trivially '' implemented minifiers , since all the browser implementations I tried run it without a...
function test ( ) { return /\//.exec ( `` \/ '' ) ; } alert ( test ( ) ) ;
Is `` \/ '' valid inside a javascript regex ?
JS
Recently I investigated a situation in which a programmer inadvertently passed undefined into addEventListener , thus : No error was thrown . It 's as if JavaScript is willing to invoke undefined . But what in the world is undefined ( ) ? I have tried all sorts of things , e.g . : but I never get anything back.Edit add...
window.addEventListener ( 'load ' , undefined ) ; console.log ( undefined ( ) === null ) ; console.log ( typeof undefined ( ) ) ;
Can not determine type of undefined ( )
JS
How could a JavaScript RegEx be written , so that it matches for example the word cube , but only if the word small is not present in the 20 character range before this word.RegEx should match : cubered cubewooden cubesmall ... ... ... ... ... .cubeRegEx should not match : small cubesmall red cubesmall wooden cube ... ...
> var regex = / ( ? : ( ? ! small ) . ) { 20 } cube/im ; undefined > regex.test ( `` small ... ... ... ... ... .cube '' ) // as expectedtrue > regex.test ( `` ... ... ... .small ... ... cube '' ) // as expectedfalse > regex.test ( `` 01234567890123456789cube '' ) // as expectedtrue > regex.test ( `` 0123456789012345678...
RegEx that matches a word that NOT succeeds another one
JS
Not sure if this is a bug or a feature . When parsing html with table elements outside a table , jQuery ignores non-table elements.passed into $ ( html ) becomesWhen passing the same html into plain javascript element.innerHTML = html becomesHere it is in action https : //codepen.io/addbrick/pen/mprBgPEDIT : Right afte...
< tr > < td > table data < /td > < /tr > < div > div after will be ignored < /div > < tr > < td > table data < /td > < /tr > table data < div > div after will be ignored < /div >
When parsing , jQuery ignores anything that is n't a table and document removes the table tag
JS
I encountered this snippet ( event handling ) from the jQuery source code : Can someone explain this to me ? How does the this.bind ( name , fn ) ; work the same as element.addEventListener ( 'event ' , 'callback ( ) ' ) ? I know the basics of javascript , but I do not know the more advanced parts of JavaScript . Since...
var events = [ 'click ' , 'focus ' , 'blur ' , … ] ; jQuery.each ( event , function ( i , name ) { jQuery.prototype [ name ] = function ( fn ) { return this.bind ( name , fn ) ; } ; } ) ;
Can someone explain this code using the .bind ( ) function to me ?
JS
I am trying to get some jQuery working on an offline page . The site 's app uses EmberJS , RequireJS , and who knows what else , but the bottom line is I am trying to replace this cryptic code with plain jQuery.Here is some HTML that should respond to interaction : Loading interaction ... RevealContent Some question So...
define ( `` site/mixins/interactions/reveal_content '' , [ `` exports '' , `` jquery '' ] , function ( exports , _jquery ) { function RevealContent ( $ el ) { this.el = $ el ; this.interactionData = $ el.find ( `` .interaction_data '' ) ; this.container = $ el.find ( `` .interaction_content '' ) ; } RevealContent.proto...
Any idea what ( 0 , _jquery [ `` default '' ] ) means in terms of jQuery selector or function ?
JS
Of course , most of the time , I can simply search for the identifier and look at all instances thereof . Often , searching for `` = '' or `` : '' will find the answer the fastest.But this technique fails is situations like this : Let 's say I have n't discovered the above code yet . As illustrated in this example , so...
// untested javascript : function AddMemberToObject ( object , value , memberName ) { object [ memberName ] = value ; } var myObj = { } // 3,000 references to myObj// ... somewhere elsevar mysteryString = thisMethodCallsAnotherMethodCallsAnotherMethodEtc ( ) ; AddMemberToObject ( myObj , someFunction , mysteryString ) ...
How can I find where an object member is defined in Javascript ?
JS
I am wondering if there is any cleaner way of injecting into a provider . As I am doing it now , I have to have http = null , and then set http = $ http in $ get so that I am able to use it in my functions . Below is my code for the providerCoffeeScript : JavaScript :
do - > githubProvider = ( ) - > http = null getUser = ( username ) - > return http.get ( `` https : //api.github.com/users/ '' + username ) .then ( response ) - > return response.data getRepos = ( user ) - > return http.get ( user.repos_url ) .then ( response ) - > return response.data getRepoDetails = ( username , rep...
Dependency Injection into Angular Provider
JS
So I 'm trying to follow a Tutorial to implement a Solar System by using THREE.js but however I 'm getting the following error : Can not read property 'appendChild ' of undefinedThis is my current code : The error is occurring at line 49 . I 've tried moving it into my on load function but that just creates even more e...
< html > < head > < meta charset = '' utf8 '' > < title > Solar System Project < /title > < script src = `` three.min.js '' > < /script > < /head > < body > < script > // Standard Variables / To be changed later . var scene , camera , render , container ; var W , H ; // On load function ... window.onload = function ( )...
'appendChild ' of undefined
JS
I recently started using react and I tend to define default values like this : instead of : What disadvantages does this approach have in contrast to using defaultProps ?
class TextInput extends Component { render ( ) { return ( < input type= '' text '' name= { this.props.inputName || 'inputName ' } style= { this.props.inputStyle || { } } className= { this.props.inputClass || `` } / > ) ; } } class TextInput extends Component { render ( ) { return ( < input type= '' text '' name= { this...
defaultProps vs logical OR
JS
This code runs for infinity , why ? if n ! =2 the function should do nothingand if n equals 2 the function calls f ( 0 ) and f ( 1 ) so it should stop after thatbut you only get infinite loop when you run it.any one could tell why ? edit : there is nothing outside the function.and no need for better code.Just asking wh...
function f ( n ) { i=0 ; if ( n==2 ) { while ( i < 2 ) { f ( i ) ; i++ ; } } }
Unexpected infinite loop
JS
I have one controller I think of as my 'root ' controller , it is the one declared with an ng-controller attribute , then a few other controllers that are instantiated dynamically via a $ routeProvider . I want to declare a function that will be available via an ng-click attribute in scope of any of the dynamic/child c...
$ scope.announce = function ( ) { alert ( $ scope.specificName ) ; }
Access the 'current ' scope from a 'root ' controller
JS
I just started Angular last week and I am struggling to access DOM from a template thats just loaded . Here 's whats happening - index.htmltemplates/top.htmlapp.jsI am not able to access dynamic elements from top.html which gets loaded in DOM later on using ng-repeat . Please let me know how to resolve this . Thanks ! ...
< div class= '' template '' ng-app= '' myApp '' ng-controller= '' myController '' > < div ng-include= '' template_url '' > < /div > < input type= '' button '' value= '' Load Top '' ng-click= '' loadTopTemplate ( ) '' > < /div > < ul > < li ng-repeat= '' ( key , myObjectItem ) in myObject '' > < span id= '' { { key } } ...
Angular - Access DOM Element From Just Loaded Template
JS
I am working on a problem where I have to group an array of objects from one form into another.An example is better than 1000 words : And the new object should look like this : I have to find unique houses with all their rooms and also to add each price from initial object inside room.I 'm wondering which would be the ...
var initialData = [ { house : { id : 1 , text : `` white '' } , room : { id : 1 , text : `` red '' } , price : 2.1 } , { house : { id : 1 , text : `` white '' } , room : { id : 2 , text : `` blue '' } , price : 3.1 } , { house : { id : 1 , text : `` white '' } , room : { id : 3 , text : `` red '' } , price : 5.8 } , { ...
Javascript object reorganization with performance
JS
Consider this snippet : which can also be written like this : If you run any of the given two codes , you 'll face this error : My question is why ? Before answering my question , please consider my argument : I understand the concept of recursion and how it leads to a stack overflow if there 's no stopping condition ....
function f ( ) { return new Promise ( ( resolve , reject ) = > { f ( ) .then ( ( ) = > { resolve ( ) ; } ) ; } ) ; } f ( ) ; async function f ( ) { return await f ( ) ; } f ( ) ; ( node:23197 ) UnhandledPromiseRejectionWarning : RangeError : Maximum call stack size exceeded while ( 1 ) { } function f ( ) { return new P...
Why recursive async functions in Javascript lead to stack overflow ?
JS
I know that using an underscore is just a convention to define private variables in JavaScript . But I came across a use case [ while using a class ] where use of _ seems mandatory to make the code work ! My question is how _ is used under the hood by get and set.The below code throws an error : RangeError : Maximum ca...
class User { constructor ( name ) { this.name = name ; } get name ( ) { return this.name ; } set name ( val ) { this.name = val ; } } let user = new User ( `` Jhon '' ) ; console.log ( user.name ) ; class User { constructor ( name ) { this.name = name ; } get name ( ) { return this._name ; // Added `` _ '' here } set n...
Why do developers use `` _ '' while using get and set in JavaScript ?
JS
i have a component which contains a component that is being render based on an if statement . the statement if false adds a css class to the container component , and not render the inner component and if true otherwise.the class is being added or not added in the right way . The inner component on the other hand is no...
< React.Fragment > < div className= { containerClasses } > < div className= '' conditions-types '' > < TableHeaderCell title= { texts.bookingReferenceInformation1 } / > { isTrue ( displayFlightBookingReference ) & & < TableHeaderCell title= { texts.bookingReferenceInformation2 } / > } { isTrue ( displayBookingDate ) & ...
jest/react - component is n't show in the snapshot
JS
The first question I was asked in the interview , and to be honest I saw myself really confused and shown the door , Consider the snippets : Case a : Case b : As per my understanding , Function must be in the prototypical chain of ins ?
var sayHello = new Function ( `` alert ( 'Hello there ' ) ; '' ) ; alert ( sayHello instanceof Function ) ; // true alert ( sayHello instanceof Object ) ; // true , since every // object inherits from Object var myFunction = function ( ) { } var ins = new myFunction ( ) ; alert ( ins instanceof myFunction ) ; // ofcour...
instanceof in case of Function in JavaScript
JS
I 'm trying to have the selected options value pass when I click the Add Another Worker button and have the pre selected= '' selected '' option removed and placed on the new selected option.JQueryHTML Here is a link to my jsfiddle https : //jsfiddle.net/jxqyn4rg/
$ ( document ) .ready ( function ( ) { $ ( '.worker ' ) .on ( 'click ' , function ( e ) { e.preventDefault ( ) ; e.stopPropagation ( ) ; var title = $ ( '.title ' ) .val ( ) ; var worker = ' < select name= '' title [ ] '' class= '' title '' > < option value= '' Select a Title '' selected= '' selected '' > Select a Titl...
How to pass and remove a selected options value
JS
This is my object literal : How can I addto obj ?
var obj = { key1 : value1 } ; { key1 : value1 , value2 , value3 }
Adding data to a JavaScript object literal
JS
I ’ m working in a web project and I decide to turn in MVC 4 from ASP.NET.After many issues which I face it , I ’ m in a position to handle the events raised from the program.In my previous environment ASPX.NET I was double clicked on a < asp : Button ... / > control and automatically in the code behind I see the relat...
ValidationSummary.ValidationGroup The view at '~ / Views / Home / Index.aspx ' must derive from ViewPage < script type= '' text/javascript '' > function logSubmit ( ) { var url = 'loginSubmit ' ; $ .ajax ( { type : 'GET ' , url : url , dataType : 'json ' , } ) ; } < /script > Public Function loginSubmit ( ) As JsonResu...
page.aspx and code behind ( page.aspx.vb ) relations problems
JS
While checking source code of a page I saw the JS code uglified as seen here : http : //jsfiddle.net/3jxzpxgv/show/Do you guys have any idea which tool is used ? I do n't think this is UglifyJS , Closure or YUI .
eval ( ( function ( D28 ) { for ( var J28= '' '' , p28=0 , C28=function ( D28 , y28 ) { for ( var L28=0 , E28=0 ; E28=32 & & t28 < =127 ) { L28+=t28-32 ; } } return L28 ; } ; p28 ( ( 0x50,48. ) > ( 54.0E1,99. ) ? 2:1.3860E3 < = ( 27.,0xA9 ) ? ( 1.95E2,0x229 ) :13.98E2 < ( 126,0x240 ) ? 2 : ( 0x1B2,0x19F ) > ( 0x9F,105 ...
Which tool used to uglify this piece of code ?
JS
I will start with an apology about my poor English . I will try to be as clear as I can . : ) I have a 3-dimensional array ( just an array of 2-dimensional arrays ) . My goal is to take one of the 2-dimensional arrays , and rotate it 90° counterclockwise . It look like this : I try to make it `` rotate '' like this : I...
[ 1|2|3 ] [ 4|5|6 ] [ 7|8|9 ] [ 3|6|9 ] [ 2|5|8 ] [ 1|4|7 ] var temp = [ ] ; var cube = [ [ [ ' A ' , ' A ' , ' A ' ] , [ ' A ' , ' A ' , ' A ' ] , [ ' A ' , ' A ' , ' A ' ] ] , [ [ ' B ' , ' B ' , ' B ' ] , [ ' B ' , ' B ' , ' B ' ] , [ ' B ' , ' B ' , ' B ' ] ] , [ [ ' C ' , ' C ' , ' C ' ] , [ ' C ' , ' C ' , ' C ' ...
Create a duplicate of an array and manipulate the original
JS
I want to extend Promise and change the then signature so its callback receives two values . I tried different approaches two of which are documented and tested here . Sadly , I get various errors or the resulting class does not behave like a Promise.Approach 1 : Wrapping a native PromiseApproach 2 : Extending native P...
export class MyWrappedPromise { constructor ( data ) { this.data = data ; this.promise = new Promise ( evaluate.bind ( data ) ) ; } then ( callback ) { this.promise.then ( ( ) = > callback ( this.data , ADDITIONAL_DATA ) ) ; } catch ( callback ) { this.promise.catch ( callback ) ; } } export class MyExtendedPromise ext...
Extending ` Promise ` and change ` then ` signature
JS
For the below code snippet , i would like to understand how NodeJS runtime handles things :1st approach : longRunningTask ( ) function will block the main thread , as expected.2nd approach : In longRunningTaskProm ( ) wrapping the same code in a Promise , was expecting execution will move away from main thread and run ...
const billion = 1000000000 ; function longRunningTask ( ) { let i = 0 ; while ( i < = billion ) i++ ; console.log ( ` Billion loops done. ` ) ; } function longRunningTaskProm ( ) { return new Promise ( ( resolve , reject ) = > { let i = 0 ; while ( i < = billion ) i++ ; resolve ( ` Billion loops done : with promise. ` ...
Difference between returning new Promise and Promise.resolve
JS
RxJs version 5.5 introduced the pipe operator to make it easier to combine RxJs operators and to make tree shaking more efficient for these situations . My question is , should you use the pipe operator if you only intend to use one operator ? Consider the following examples : vsIn situations such as this where you onl...
someObservable.map ( mappingLogicMethod ) .subscribe ( x = > console.log ( x ) ) ; someObservable.pipe ( map ( mappingLogicMethod ) ) .subscribe ( x = > console.log ( x ) ) ;
Should I use the pipe operator if I only use one operator ?
JS
How can I made new array from firsts elements of arrays from this array ? and I want it to be My attempt :
[ [ `` 1 '' ,2 ] , [ `` 3 '' ,2 ] , [ `` 6 '' ,2 ] ] [ ' 1 ' , ' 3 ' , ' 6 ' ] var newArray = [ ] for ( i = 0 ; i < arrayToCompare.length - 1 ; i++ ) { newArray.push ( arrayToCompare [ [ 0 ] ] ) }
How can I made new array from firsts elements of arrays from an array
JS
I have tried two versionThe first one autoplay is working on Google Chrome but how can I control with button that I can play or pause the audio ? The second one autoplay is not working on Google Chrome but I can control it with button in IE or FireFoxThe buttonsAnd the JavascriptSo how can I deal with this problem ? I ...
< embed name= '' pop '' src= '' pop.mp3 '' loop= '' true '' hidden= '' true '' autostart= '' true '' > < audio id= '' myAudio '' > < source src= '' pop.mp3 '' type= '' audio/mp3 '' > < /audio > < button onclick= '' playAud ( ) '' type= '' button '' > Play < /button > < button onclick= '' pauseAud ( ) '' type= '' button...
How can I control background music with button ?
JS
I have the following code in JSfiddle.But when I paste the same exact code inside Chrome console , the function five ( ) prints 5 . Why ?
var a = 1 ; function five ( ) { this.a = 5 ; console.log ( a ) ; //JSfiddle prints the value 1 } five ( )
Why do JSfiddle and Chrome console return different values of the same function ?
JS
I have a bunch of arrays in this form : Lets say I would like to sort the first row ascending by val , so it becomes : Is there an easy way to sort the remaining arrays , so that their order matches the idx-order of the sorted first row ? Maybe this is even possible without the idx property ?
var myRows = [ [ { idx : 0 , val : 90 } , { idx : 1 , val : 75 } , { idx : 2 , val : 35 } ] , [ { idx : 0 , val : 50 } , { idx : 1 , val : 17 } , { idx : 2 , val : 95 } ] , [ { idx : 0 , val : 10 } , { idx : 1 , val : 24 } , { idx : 2 , val : 80 } ] // ... ] ; [ { idx : 2 , val : 35 } , { idx : 1 , val : 75 } , { idx :...
Sort other arrays by order of specific array ?
JS
I do n't know if SO is the right place for such a question.I know a bit Promises , and I use them in a Node/Express environment to 'fix ' the asynchronous behavior of Node when querying database ( = Wait for DB answer , then do something ) .However , the more I use them , the less I know when not use them.For example ,...
... . for ( var i = 0 ; i < rows.length ; i++ ) { // loop over a CSV file by line var cell = rows [ i ] .split ( / ; / ) var origin = cell [ 1 ] var destination = cell [ 2 ] var id = cell [ 0 ] Promise.all ( [ origin , destination , id ] ) .then ( ( p ) = > { } ...
Using 'Promise ' vs. NOT using 'Promise ' : in which cases ?
JS
How comeproduces SyntaxError : Unexpected token ( whilealerts `` test123 '' ?
function ( ) { alert ( `` test123 '' ) ; } ( ) ! function ( ) { alert ( `` test123 '' ) ; } ( )
anonymous javascript function call ! function vs function
JS
I have a bunch of JSON string returned from an ajax call in a specific format and when starting to convert them all into my own Javascript object , I start to wonder if there is any easier way since we 're talking Javascript here.I 'll have var manyOfThem = [ { name : ' a ' } , { name : ' b ' } , { name : ' c ' } ] ; A...
myClass.prototype.doSomething = function ( ) { // do something to this.name } ; $ .each ( manyOfThem , function ( index , item ) { item.doSomething ( ) ; } ) ; var myClass = function ( item ) { this.name = item.name ; // do the same for the rest of item 's potentially 20 properties } ; var oneOfThem = new myClass ( man...
Javascript turning JSON string into instance of function
JS
When I execute the following code , it behaves like I expect ( logs the contents of the DIV element ) : What I ca n't understand is why the following code does NOT work : They seem the same , so why does the DIV selector work when the FORM selector does not ?
var html = ' < form action= '' / '' method= '' get '' name= '' myform '' > < div > 123 < /div > < /form > ' ; console.log ( $ ( 'div ' , html ) ) ; var html = ' < form action= '' / '' method= '' get '' name= '' myform '' > < div > 123 < /div > < /form > ' ; console.log ( $ ( 'form ' , html ) ) ;
Form selector not work working on dynamic markup
JS
I have search page in my NextJS application . URL example - /search ? q=Naaarutoo . And for example after reloading I just want to set `` Naaarutoo '' as the input value ( I know how to set query param to input value ) IMMEDIATELY . If we look closer we will see that field did n't fulfilled : I think this is because th...
import React from 'react'import { Formik , Form , Field } from 'formik'const Search = ( { router : { query } } ) = > ( < Formik enableReinitialize onSubmit= { ( ) = > { } } initialValues= { { q : query.q || `` } } render= { ( ) = > ( < Form > < Field name= ' q ' type= '' search '' placeholder= '' Find something '' / > ...
Fill the field immediately after reloading the page
JS
Looking between the very first line of code in Bootstrap 's minified and unminified JS file , there is an immediate discrepancy : vs. ( See for yourself : bootstrap.js and bootstrap.min.js ) I 'm confused why this is allowed . My ( perhaps naïve ) understanding is that === is always a performance gain , and often preve...
// bootstrap.jsif ( typeof jQuery === 'undefined ' ) { ... } // bootstrap.min.jsif ( `` undefined '' ==typeof jQuery ) ...
Why do Javascript minifiers convert === to == ?
JS
Why is the `` instanceof '' result not `` false '' , because the `` constructor '' does n't refer to itself but the inherited prototype ?
function Foo ( ) { } function Bar ( ) { } Bar.prototype = new Foo ( ) console.log ( `` Bar.prototype.constructor === Foo ? `` + ( Bar.prototype.constructor === Foo ) ) console.log ( `` new Bar ( ) instanceof Bar ? `` + ( new Bar ( ) instanceof Bar ) ) = > Bar.prototype.constructor === Foo ? true= > new Bar ( ) instance...
Confusing `` instanceof `` result
JS
I use .fnUpdate ( ) to generate table according to data that comes from the database.http : //legacy.datatables.net/refI have some teacher in the header of the table , and some information in the td in the body of the table.I can generate the data in TDs but I want to show the multiple td bellow one th.ProblemI can set...
< script src= '' https : //cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js '' > < /script > < script src= '' http : //code.jquery.com/jquery-1.11.3.min.js '' > < /script > < link href= '' https : //nightly.datatables.net/css/jquery.dataTables.css '' rel= '' stylesheet '' type= '' text/css '' / > < script src=...
fnUpdate the multi td for th with colspan
JS
I would like to change the result of my form 's data before submitting but I am struggling with my scriptMy HTMLJavascript : I am trying to get a result like or similar to this.NoteThere is a possibility of having multiple rows ( not only 2 ) and they are not named row_n the name is just for example purpose
< form > < table > < tr class= '' row_1 '' > < td > < input name= '' flavour_1 '' type= '' text '' > < br > < input name= '' flavour_2 '' type= '' text '' > < /td > < td > < input name= '' taste_1 '' type= '' text '' > < br > < input name= '' taste_2 '' type= '' text '' > < /td > < /tr > < tr class= '' row_2 '' > < td ...
Manipulate form 's data result
JS
I created 2 instances of a prototype , changed a function in prototype , changes reflected in both the instances ( Great ) .However , when I modified the prototype by removing the function , the function still existed for the existing instances.Line 1 and 2 are working as expected and after setting the protoype back to...
function A ( ) { this.name = `` cool '' ; } A.prototype = { howCool : function ( ) { return this.name + `` er '' ; } } ; var a1 = new A ( ) , a2 = new A ( ) ; a1.name = `` hot '' ; //line1console.log ( a1.howCool ( ) ) ; //line2console.log ( a2.howCool ( ) ) ; A.prototype = { } ; //line3console.log ( a1.howCool ( ) ) ;...
Javascript : Modifying Prototype does n't affect existing Instances
JS
I do n't have the liberty of testing my Javascript on a foreign operating system . I would like to know if the following will work globally : If a Spanish OS were to run this , would it crash ? Would I have to use this instead ? I use strings to initialize Date because I hate using the numerical approaches which all re...
var d = new Date ( 'Tue Aug 20 2011 16:00:00 GMT-0700 ( Pacific Daylight Time ) ' ) ; var d = new Date ( 'Mar Ago 20 2011 16:00:00 GMT-0700 ( Pacífico Hora de verano ) ' ) ;
How is Javascript Date handled in other languages ?
JS
http : //jsfiddle.net/Lx9h2smh/The problem is If I type a value in textBox say 3434 and now I want to make it 35434 by putting cursor after 3 and pressing 5 , it works fine in Firefox and IE but in chrome the 5 get added after value and it becomes 34345.The culprit line is one which replace non numeric characters.How t...
< div > < input type= '' text '' class= '' allownumericwithdecimal '' / > saadad < /div > $ ( `` .allownumericwithdecimal '' ) .live ( `` keypress keyup `` , function ( event ) { $ ( this ) .val ( $ ( this ) .val ( ) .replace ( / [ ^0-9\ . ] /g , `` ) ) ; var text = $ ( this ) .val ( ) ; if ( ! ( ( event.which > = 48 &...
Strange .replace ( ) behaviour in Chrome browser
JS
I am learning javascript , and I have read somewhere the following code : I understand that the Object.create function return a new object which inherited the object ' o ' that has been passed as a parameter to the Object.create function . But , I do n't understand what is the sense to make this ? I mean , even the Obj...
if ( typeof Object.create ! == 'function ' ) { Object.create = function ( o ) { function F ( ) { } F.prototype = o ; return new F ( ) ; } ; } newObject = Object.create ( oldObject ) ;
Newbie : Need some explanation on this js code
JS
I am trying to figure out a Modal Box Dynamically using jQuery without a form .
< a href= '' # openModal '' > Open Modal < /a > < div id= '' openModal '' class= '' modalDialog '' > < div > < a href= '' # close '' title= '' Close '' class= '' close '' > X < /a > < h2 > Modal Box < /h2 > < p > This is a sample modal box that can be created using the powers of CSS3. < /p > < p > You could do a lot of...
I am trying to figure out closing a Modal Box Dynamically using jquery without a form
JS
I 'm reading through the MobX docs and I 'm confused by the following code : What is the significance of the @ symbol ?
class Todo { id = Math.random ( ) ; @ observable title = `` '' ; @ observable finished = false ; } @ observerclass TodoListView extends Component { render ( ) { return < div > < ul > { this.props.todoList.todos.map ( todo = > < TodoView todo= { todo } key= { todo.id } / > ) } < /ul > Tasks left : { this.props.todoList....
What is the @ used for in JavaScript ?
JS
What is the best way to handle state changes in a deep node which also need to be handled by a parent node . Here is my situation : Whenever someone is changing anything in the column property I only have to maintain the state of this value within that Column component . However , I now would like a sum of these values...
< Table > < Row prop= { user1 } > < Column prop= { user1_col1 } / > < Column prop= { user1_col2 } / > < /Row > < Row prop= { user2 } > < Column prop= { user2_col1 } / > < Column prop= { user2_col2 } / > < /Row > < TableFooter > < FooterColumn prop= { sum1 } / > < FooterColumn prop= { sum2 } / > < /TableFooter > < /Tabl...
React event hierarchy issue
JS
i need to use slideDown function from jQuery , which requires the content to be animated to be put under class `` .hide `` , for .hide I had this in my custom css : which conflicted with Bootstrap css as it contains : thus when i linked both these stylesheets , slideDown was'nt working , then i tried diffrent variation...
.hide { display : none ; } .hide { display : none ! important ; }
bootstrap blocking jquery function
JS
I was looking at nice timeline script and wanted to use , i made several change to css as per my design but I was wondering if i could change the color of active year from gray to red when page is being scrolled , I looked at the code and found that when page is scrolled no class is changed to relect sticky behaviour o...
# timeline h3 { position : -webkit-sticky ; position : sticky ; top : 5rem ; color : # 888 ; margin : 0 ; font-size : 1em ; font-weight : 400 ; } @ charset `` UTF-8 '' ; @ import url ( https : //fonts.googleapis.com/css ? family=Fira+Sans:200,400,500 ) ; * { border : 0 ; margin : 0 ; padding : 0 ; } html { height : 100...
Change color of Sticky text when its active
JS
I 'm having trouble coming up with this stream.What I 'm looking for is something like debounceTime but with priority.So if I have events with the shape { type : ' a ' , priority : 2 } . These events needs to be debounced by a few seconds but instead of the last event being emitted , the event with the highest priority...
input stream : -- -- -- ( a|1 ) -- ( b|3 ) -- - ( c|2 ) -- -- -- -- -- -- -- -- -- -- -- - ( a|1 ) -- -- -- -- -- -- -- -- -output stream : -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ( b|3 ) -- -- -- -- -- -- -- -- -- -- - ( a|1 ) -- -- -
RxJS Debounce with priority
JS
I am learning VueJs , in this sandbox https : //codesandbox.io/s/o29j95wx9 it has lines like thisWhat does the ... in ... this. $ listeners , do ? I tried searching for it but every search engine filters out that query . I do n't know what it 's called.I also see it used in vuex like this
< script > export default { props : { value : { type : String , default : `` , } } , computed : { listeners ( ) { return { // Pass all component listeners directly to input ... this. $ listeners , // Override input listener to work with v-model input : event = > this. $ emit ( 'input ' , event.target.value ) } } } } < ...
What does the ... do in Javascript ?
JS
Suppose I create an object factory like so : Now suppose I create hundreds of instances of this object : Does each obj1 , obj2 , ... store their own copy of obj.add or do they all contain a reference to a single instance of obj.add stored in memory ? Thanks !
var newObj=function ( x ) { var obj= [ ] obj.x=x obj.add=function ( n ) { return this.x+n } return obj } var obj1=newObj ( 1 ) var obj2=newObj ( 2 ) ...
efficiency of anonymous function storage
JS
I have a list from DB which is displayed in select multiple tags : Given an array of values from DB , need to select only those items that are found in the DB array , for example [ 2,4,7 ] . How do I push , with jQuery , attr ( 'selected ' ) to these option tags ? Like above .
< select multiple= '' multiple '' id= '' list '' name= '' color '' > < option value= '' 1 '' > Red < /option > < option value= '' 2 '' > Green < /option > < option value= '' 3 '' > Blue < /option > < option value= '' 4 '' > Magenta < /option > < option value= '' 5 '' > Black < /option > < option value= '' 6 '' > Cyan <...
Set selected option to multiple list using jQuery
JS
What is the best way to detect runs of dom elements in jQuery ? For instance , if I have the following list of itemsSay I want to grab all the li.foo elements and wrap them inside their own < ol > block ( or any wrapper for that matter ) to end up with something like.As you can see from the example , I only want to wra...
< ol > < li class= '' a '' > < /li > < li class= '' foo '' > < /li > < li class= '' a '' > < /li > < li class= '' a '' > < /li > < li class= '' foo '' > < /li > < li class= '' foo '' > < /li > < li class= '' foo '' > < /li > < li class= '' a '' > < /li > < li class= '' foo '' > < /li > < li class= '' foo '' > < /li > <...
Detecting `` runs '' of DOM elements in jQuery
JS
I am trying to make a menu appear from right side by jQuery animation by clicking on a span which have runmenu class but it does not work , I made the same class for a button and it worked fine , what is the problem here and why it works for button only ? !
$ ( document ) .ready ( function ( ) { $ ( `` .runmenu '' ) .click ( function ( ) { $ ( `` .menu '' ) .animate ( { `` right '' : 0 } , 1000 ) ; } ) ; } ) ; /* Global*/.conatianer { width : 1026.66px ; } /*End global*//*Start navbar*/.navbar { position : relative ; background : url ( http : //vividmarketinginc.com/wp-co...
Span element does not run the animation from jQuery
JS
I have an array of objects that I wish to sort by some grouping property data and a string telling me which property to group by ( eg : 'Organization ' or 'Organization.Name ' ) I need to write a function which takes in data that looks like beforeData and returns afterDataInput : Output : How would I go about accomplis...
beforeData = [ { 'name ' : 'John Doe ' , 'Id':1 , 'Organizations ' : [ { 'Id':12 , 'LongName ' : 'Group A ' } , { 'Id':13 , 'LongName ' : 'Group B ' } ] } , { 'name ' : 'FooBar ' , 'Id':2 , 'Organizations ' : [ { 'Id':13 , 'LongName ' : 'Group B ' } , { 'Id':14 , 'LongName ' : 'Group C ' } ] } , { 'name ' : 'Kristine B...
Given an array of objects how do I sort the objects by a property in depth n
JS
In Chrome , the following code does not display the < h1 > Hello < /h1 > until after the alert is shown and the user clicks ok . However , in Firefox the expected sequence happens , < h1 > Hello < /h1 > is displayed and then the alert appears.I 'm curious why Hello shows up after the alert is closed in Chrome . Is that...
< h1 > Hello < /h1 > < script > alert ( 'Hello is displayed after this alert ' ) < /script >
HTML before an alert is not shown
JS
I do n't know too much about the JavaScript garbage collector , just that it attempts to manage references so that unreferenced objects can be periodically purged from memory . I was thinking about something that I thought might improve performance if it was feasible by the language implementers.It would go something l...
`` no gc '' ;
can objects be marked not to be garbage collected ?
JS
In golang there is the _ ( Blank Identifier ) . this way you can omit the 2nd and 3rd return values of a function.In javascript is it possible to do this ?
myValue , _ , _ : = myFunction ( ) function myFunction ( ) { return [ 1,2,3 ] } // Something like thisconst [ first , _ , _ ] = myFunction ( )
Blank identifier in Javascript
JS
I am currently learning Javascript.I 've read that an object which has an internal member [ [ Call ] ] produces function as the result of typeof that object.I wonder whether I can set this internal member in my Javascript code , i.e . is something like this possible ? : And if it is possible , would this change the res...
function my_foo ( ) { } var my_obj = { } ; // is the ' ; ' an empty statement ? my_obj [ `` [ [ Call ] ] '' ] =my_foo ; // in my test , this did n't work
Transform a Javascript Object to Function manually
JS
I 'm still learning Angular and have started to create a simple website . I have routing and some logic in my view to have an active class on the menu item when the url is on that page . The problem I am starting to see is if I change the url from / to /home I have to update it in the routing and view and also the logi...
angular.module ( 'simpleApp ' , [ 'ngRoute ' ] ) .config ( [ ' $ routeProvider ' , ' $ locationProvider ' , function ( $ routeProvider , $ locationProvider ) { $ routeProvider .when ( '/ ' , { templateUrl : 'views/home/index.html ' } ) .when ( '/about ' , { templateUrl : 'views/about/index.html ' , controller : 'AboutC...
DRY up logic in view as well as $ routing
JS
say I have an array [ [ `` a '' , `` b '' ] , [ `` c '' , `` d '' ] ] how can I iterate or reduce or map or join this array and get [ `` ac '' , `` ad '' , `` bc '' , `` bd '' ] and if array is like [ [ `` a '' , `` b '' ] , [ `` c '' , `` d '' ] , [ `` e '' , `` f '' ] ] I should get like [ `` ace '' , `` acf '' , `` ...
const output = [ ] ; const sol = array.reduce ( ( cum , ind ) = > { for ( let i = 0 ; i < = cum.length ; i++ ) { for ( let j = 0 ; j < = ind.length ; j++ ) { output.push ( ` $ { cum [ i ] } + $ { ind [ j ] } ` ) ; } } } ) ; console.log ( output ) ;
iterate array of arrays and concat in javascript
JS
In python , I can do the following , to conditionally use a 2nd list if a 1st one is empty : In javascript , however , So , if the `` or trick '' is off the table , I 'm wondering whats the most concise way to do something like the following if-javascript-were-python-this-would-work pseudocode :
> > > x = [ ] or [ 1 , 2 ] > > > x [ 1 , 2 ] > > > x = [ ] || [ 1 , 2 ] ; [ ] $ elems = $ ( 'first-selector ' ) || $ ( 'second-selector ' )
jquery : is there a concise way to conditionally use a 2nd selector if a 1st selector comes back empty ?
JS
I have the following key/value objectSo each key has an object with a value and a hidden attribute , I 'm stuck on how to achieve the following.Transform the nested object so each key just has it 's value . Not the object with value and hidden . The big issue it seems for me is that it 's nested.. So it has to work rec...
form : { id : { value : this.item.id , hidden : true } , title : { value : this.item.title } , translations : { en : { locale : { value : 'en ' , hidden : true } , name : { value : 'Hello World ' } } , nl : { locale : { value : 'nl ' , hidden : true } , name : { value : 'Hallo Wereld ' } } } } form : { id : this.item.i...
Transform an object with objects in it
JS
why this kind of bad design is made on js ? Is there any special reason to design the automatic semicolon insertion like this ? Here is my code , It is not work in js in chrome : Here is the error : I know the right version of this code is : I just want to know why js syntax is designed so stupid . History reason ? I a...
( function ( ) { console.log ( `` abc '' ) ; } ) ( ) ( function ( ) { console.log ( `` 123 '' ) ; } ) ( ) ; Uncaught TypeError : ( intermediate value ) ( ... ) is not a function ( function ( ) { console.log ( `` abc '' ) ; } ) ( ) ; ( function ( ) { console.log ( `` 123 '' ) ; } ) ( ) ; x=1 ( function ( ) { console.log...
why a newline between parentheses of two function calls not treat as two statements in js ?
JS
If I execute the statementwill I actually get an instance of moo ? This seems at both the same time obvious and non-intuitive . Functionally , this is what should happen , but at the same time this is not-expected if you did n't know the internals.EDIT : I realized this seems unintuitive b.c . in Java constructors can ...
var foo = function ( ) { return new moo ( ) ; } var moo = function ( ) { return this ; } new foo ( )
Will new return the named function constructor instance- ?