lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I need when mouseentercurrent div append some text into div but not work good sometimes show sometimes no here is fiddle examplecode :
$ ( document ) .ready ( function ( ) { var thmb_wrap = $ ( '.thm-img ' ) ; var thumb = $ ( '.thm-img img ' ) ; var outer = $ ( '.mn-img ' ) ; var full = $ ( '.mn-img img ' ) .length ; var sc_height = $ ( outer ) .height ( ) ; thmb_wrap.one ( 'mouseenter ' , function ( ) { var cur_im = $ ( '.thm-img img ' ) .index ( $ (...
mouseenter and append not work good
JS
I have a function which creates a tooltip for specific objects . Currently , I am running a tooltip function after ajax insertions to create and append the new tooltip objects . I am curious if there is a way to use .on ( ) to auto-run the tooltip function on insertion , rather than manually running it . For instance :...
$ ( ' [ title ] ' ) .on ( 'inserted ' , function ( ) { tooltip ( this ) ; } ) ;
JQuery - using .on with element insertion
JS
I 'm just learning how to use JS higher-order functions ( map , forEach , reduce , etc ) , and have stumbled into confusion . I 'm trying to write a simple 'range ' function , but ca n't seem to populate my output array . This is the goal : I 'm getting this : Here is my code : What am I missing here ? As far as I can ...
range ( 1 , 4 ) // [ 1 , 2 , 3 , 4 ] [ undefined × 4 ] function range ( num1 , num2 ) { var rangeArr = new Array ( ( num2 + 1 ) - num1 ) ; return rangeArr.map ( function ( e , i , arr ) { return arr [ i ] = num1 + i } ) ; } function bleck ( ) { var blah = [ 1 , 2 , 3 , 4 ] ; var x = 'wtf ' ; return blah.map ( function ...
forEach on a 'new Array ' is n't doing what I expect
JS
I have this html : And using this jquery I 'm trying to replace the word ok with cool , as long as the word ok is not inside the span # notOk . I also want to preserve the sentence and not move any words around , which is what happened when I tried . I guess I 'm looking for something like dontGetElementByID ( `` ) . ?...
< div id= '' content '' > This following word is not < span id= '' notOk '' > ok < /span > but all the other words are ok < /div > var content = $ ( ' # content ' ) .html ( ) content = content.replace ( 'ok ' , 'cool ' ) ; $ ( ' # content ' ) .html ( content )
How do u replace a string that 's not inside a specific div ?
JS
I am writing a script where you can add and remove a drop-down list of languages . I got it working but my question is if there is a way to externalize the select tag part of the code as I would have more than 100 options and load it in JavaScript when a link is click . I do n't want to have 100 option tags within the ...
$ ( function ( ) { var scntDiv = $ ( ' # container ' ) ; var i = $ ( ' # container p ' ) .size ( ) + 1 ; $ ( ' # addScnt ' ) .live ( 'click ' , function ( ) { $ ( ' < p > < select > I DONT WANT TO HAVE 100 OPTION TAGS HERE < /select > < /p > ' ) .appendTo ( scntDiv ) ; i++ ; return false ; } ) ; } ) ;
How to load an external file in JavaScript ?
JS
Working code sample.Trivial markup : Trivial code sample : And really strange scope behaviour . Can you please explain why this happens ?
< ! DOCTYPE html > < html ng-app= '' APP '' > < head > < /head > < body ng-controller= '' myController '' > < script src= '' angular.min.js '' > < /script > < script src= '' controller.js '' > < /script > < /body > < /html > angular.module ( 'APP ' , [ ] ) .controller ( 'myController ' , function ( $ scope ) { $ scope....
Angular unexpected behaviour . Self-executing function calls scope function
JS
The facts : I have no jQuery experience or knowledge and this is my first ever question on Stack Overflow.The need : I 'm building a website using Bootstrap 3.3.6 with multiple , very complex data tables that have to be dynamically stacked on mobile devices via CSS . The column header has to be repeated otherwise the t...
( function ( ) { `` use strict '' ; var tableIds = Array ( ) ; $ ( 'table ' ) .each ( function ( tid ) { if ( tableIds ) { tableIds [ tid ] = $ ( this ) .attr ( 'id ' ) ; } var currentId = tableIds [ tid ] ; alert ( 'Id is : ' + currentId ) ; } ) ; var header = Array ( ) ; /*get titles from the headings*/ $ ( 'thead tr...
How do I prevent a jQuery function ( that reads title attributes on 1st row th 's of thead 's ) to apply retrieved titles to all tables in a document ?
JS
There is an example of infinite scroll to bottom.There is an jsfiddle exampleHow do I make infinite scroll like this but to top with js ?
var $ ol = document.querySelector ( `` ol '' ) ; function load_more ( ) { var html = `` '' ; for ( var i = 0 ; i < 5 ; i++ ) html += ' < li > < /li > ' ; $ ol.innerHTML += html ; } $ ol.addEventListener ( `` scroll '' , function ( ) { if ( $ ol.scrollHeight - $ ol.scrollTop === $ ol.clientHeight ) load_more ( ) ; } ) ;...
How do I make Infinite Scroll to top with js ?
JS
I 'm creating a simple hang man like game . The user can input a `` secret sentence '' and then the players have to guess it by chosing letters one by one.Since this game will be used in several languages , I would like to solve all accented character if a player chose the non-accented character . For example : If the ...
IL CANE È BELLO . function isAccentedVowel ( chosenChar , currentChar ) { console.log ( 'The user selected this char : ' + chosenChar ) console.log ( ' I\ 'm comparing it to this char : ' + currentChar ) switch ( chosenChar ) { case ' E ' : if ( currentChar === ' È ' ) return true ; } }
JavaScript : Comparing characters and accented characters
JS
My question is about the Mozilla developer page : typeof operatorIn the example chapter , whenever a comparison of the following form is done they comment it : Although they never explain why . It 's easy to see why it 's a silly way of going about type-checking , but I 'm curious as to the reason why they went out of ...
typeof Number ( 1 ) === 'number ' ; // but never use this form !
Mozilla developer page - But never use this form
JS
Extracting this table into an arrayThe number of headers is not known in advanceto help , headers gives merows gives meIf I try and combine these arrays I get something like As you can see this is not quite right and I need to do the array of arrays instead.. Something likeCan someone help ? I 'm not really a JS person...
$ ( function ( ) { var $ table = $ ( `` # results '' ) , $ headerCells = $ table.find ( `` thead th '' ) , $ rowCells = $ table.find ( `` tbody tr td '' ) ; var headers = [ ] , rows = [ ] , combined = [ ] ; $ headerCells.each ( function ( k , v ) { headers [ headers.length ] = $ ( this ) .text ( ) ; } ) ; $ rowCells.ea...
javascript copy array into new array based on number of headers
JS
While working on a project I ran across a bug and found this unexpected behaviour : If I call .replace ( ) on a string and set the result to a div using .text ( ) the replace function works as I expect.However , if I call .replace ( ) on a string and set the result to a div using .html ( ) , the targeted text is not re...
$ ( ' # result1 ' ) .text ( '¤cyId'.replace ( '¤cyId ' , ' & currencyId ' ) ) ; // works $ ( ' # result2 ' ) .html ( '¤cyId'.replace ( '¤cyId ' , ' & currencyId ' ) ) ; // doesnt work var result = '¤cyId'.replace ( '¤cyId ' , ' & currencyId ' ) $ ( ' # result3 ' ) .text ( result ) ; // works $ ( ' # result4 ' ) .html (...
Why does using .html ( ) break this Replace expression ?
JS
I 'm using a function that transcribes strings into a byte array , I have this function in PHP and JavaScript but both have different behaviors when I play these characters : 㬁愃膘ƘჀ䚐⦀飠噋 & ӡ๨㏃棱쌌ص䌠How to make the results are the same ? My code :
function bytesFromWords ( $ string ) { $ bytes = array ( ) ; $ j = strlen ( $ string ) ; for ( $ i = 0 ; $ i < $ j ; $ i++ ) { $ char = ord ( mb_substr ( $ string , $ i , 1 ) ) ; $ bytes [ ] = $ char > > 8 ; $ bytes [ ] = $ char & 0xFF ; } return $ bytes ; } echo bytesFromWords ( '㬁愃膘ƘჀ䚐⦀飠噋 & ӡ๨㏃棱쌌ص䌠 ' ) ; // result : ...
array of output bytes difference version of php
JS
An app is using Cordova with InAppBrowser plugin version 3.2.1 to load a webpage built in Asp.Net 4.5.2 . We have been experiencing erratic behaviour , so I 've made a page to catch the problem and share it here.This page contains a really simple button executing JS within the onclick event : It works perfectly , but w...
< button onclick= '' alert ( ' 1 ' ) ; alert ( ' 2 ' ) ; alert ( ' 3 ' ) ; '' > EXECUTION < /button > < button id= '' testButton '' > Test < /button > $ ( document ) .ready ( function ( ) { $ ( `` # testButton '' ) .click ( function ( ) { alert ( ' 1 ' ) ; alert ( ' 2 ' ) ; alert ( ' 3 ' ) ; } ) ; } ) ; $ ( `` # testBu...
Javascript executing backwards
JS
I have a few onclick and on mouseover events in my html generated by PHP , something like this : I wish to make use of unbind on the mouseover but it has n't worked when I tried this : So I am guessing unbind will only work with events created by JQuery ? Is there something else I can try ? Btw , I ca n't move my event...
< div onmouseover= '' fave ( 'heart_ < ? php echo $ row [ 'id ' ] ; ? > ' ; '' class= '' heart '' > < a href= '' '' > < /a > < /div > $ ( ' # '+ id ) .unbind ( 'mouseover ' ) ;
Unbind Events with JQuery : Does it work with events setup in HTML ?
JS
I am using eval function in a weird way , as a constructor.It throws error as , As the error message shows , eval is a function but not a constructor.The question is , do n't all javascript functions act as constructors as well ?
try { var y = new eval ( ) } catch ( error ) { console.log ( `` caught a `` + error.name + `` : `` + error.message ) ; } caught a TypeError : function eval ( ) { [ native code ] } is not a constructor
Are n't all JavaScript functions constructors as well ?
JS
I am working on a CRM we inherited . Long story short - there is a button that calls a php script which should run in background and we do n't need to wait for response . Now , the transferInTimeExec.php takes an hour to run , it 's a very complex script that deals with weekly timesheets for a recruitment company , pro...
request ( idata+'transferInTimeExec.php ' , { sync : false , preventCache : true , method : 'GET ' } ) ;
Dojo : all xhr / ajax calls seem to be synchronous and block other calls
JS
I´m learning javascript ES6 and I just spotted with -infinity on my console when I run this code : What does it mean ? Regards
let numeros = [ 1 , 5 , 10 , 20 , 100 , 234 ] ; let max = Math.max.apply ( numeros ) ; console.log ( max ) ;
javascript console -infinity , what does it mean ?
JS
I 'm trying to turn an image source into a string so I can run substring ( ) on it . I used the following JavaScript to get the source : Of course , as I soon found out , this returned an object instead of a string . I tried running .toString ( ) on the ImageType variable , but that did n't work . Is there something I ...
function ShowQuizAnswers ( quiz ) { var QuizImage = document.getElementById ( quiz ) ; var ImageType = QuizImage.attributes.src ; console.log ( ImageType ) ; }
How do I return an image source as a string ?
JS
The MDN documentation for async function currently gives the following combined example of two ways to use await . I 've reordered it just a bit for emphasis : This was a bit surprising to me . Why doesresolve the two promises sequentially , whileseemingly resolves the two promises simultaneously ? Is this behavior spe...
function resolveAfter2Seconds ( x ) { return new Promise ( resolve = > { setTimeout ( ( ) = > { resolve ( x ) ; } , 2000 ) ; } ) ; } async function add1 ( x ) { const a = await resolveAfter2Seconds ( 20 ) ; const b = await resolveAfter2Seconds ( 30 ) ; return x + a + b ; } async function add2 ( x ) { const p_a = resolv...
When is ` await ` resolved simultaneously ?
JS
Basically , I 'm generating a random graph with D3.js and I would like to generate a random fill-color and border-color for each node , the border color has to be a shade of the fill color.I 'm currently using something like this to generate random fill-color : But the border is also random so it 's not linked with the...
randomColor ( ) { const r = ( ) = > Math.floor ( 256 * Math.random ( ) ) ; return { color : ` rgb ( $ { r ( ) } , $ { r ( ) } , $ { r ( ) } ) ` , border : ` rgb ( $ { r ( ) } , $ { r ( ) } , $ { r ( ) } ) ` } ; }
How can I generate 2 colors where one of them is a shade of the other one ?
JS
This function is supposed to change the background color of the object being clickedI call it like this and it changes the background of this divThe problem is that I want to do something else before running colorMe . So I ca n't use just $ ( '.colorme ' ) .click ( colorMe ) ; . What I 'm trying to do is something like...
function colorMe ( ) { $ ( this ) .css ( 'background-color ' , 'red ' ) ; } $ ( '.colorme ' ) .click ( colorMe ) ; < div class= '' colorme '' > Color Me < /div > $ ( '.colorme ' ) .click ( function ( ) { alert ( 'something happens first , then colorMe is called ' ) ; colorMe ( ) ; //I call colorMe here.. $ ( this ) .co...
why is this code not targeting the right selector
JS
I have a code that allows me couple things like only digit backspace . How can I change the regex that it will allow to press `` enter '' and allows only 1 comma and after the comma max 2 numbers ?
$ ( `` [ name=price ] '' ) .keydown ( function ( e ) { if ( e.keyCode == 110 || e.keyCode == 190 ) { e.preventDefault ( ) ; $ ( this ) .val ( $ ( this ) .val ( ) + ' , ' ) ; } if ( /\d| , +| [ b ] +|-+/i.test ( e.key ) ) { } else { return false } } )
Only allow 1 comma and 2 decimal after it
JS
I am Currently having trouble change the value of a drop down list . I am currently adding an item to my cart on https : //www.reebok.com/us/cart . I am trying to change the quantity.I am trying to rewrite my java code into javascript . With that being said.Currently works for me in java using the Selenium library . Bu...
Select select = new Select ( driver.findElement ( By.xpath ( `` //* [ @ id=\ '' app\ '' ] /div/div/div/div/div [ 2 ] /div/main/div [ 1 ] /div/div/div/div/div/div [ 2 ] /div [ 2 ] /div [ 2 ] /div/div/select '' ) ) ) ; select.selectByVisibleText ( 5 ) ; var select= document.evaluate ( '//* [ @ id= '' app '' ] /div/div/di...
Changing selected value in a select option
JS
I want to be able to keep track of how many arrays a certain program uses , so that I can figure out if unnecessary memory has been allocated.The problem I am running into is Javascript 's construct that array literal [ ] does not trigger Array # constructor . Is there another way for me to keep track of array usage ? ...
var arrayConstructor = Array // store referencewindow.arrCount = 0window.Array = function ( ) { arrCount++ ; return new Array ( ) ; } var arr1 = new Arraywindow.arrCount // 1var arr2 = [ ] window.arrCount // 1 : NOT WORKING !
How to keep track of how many arrays are created in Javascript ?
JS
I have a form in a fluid design consisting of a series of labels and fields , where I want them to flow one after another and wrap down if necessary to support the width of the window . ( The label and input must flow as a unit , no dangling label at the end of one row with its input on the next row . ) But when they w...
.wrapped-fields label { display : inline-block ; } .wrapped-fields label > span { display : inline-block ; width : 8em ; white-space : nowrap ; } < form class= '' wrapped-fields '' > < label > < span > Short : < /span > < input type= '' text '' size= '' 5 '' > < /label > < label > < span > Long label for field : < /spa...
Form with label+field units wrappable , but then lining up nicely when wrapped
JS
I am curious how Underscore 's _.now method is faster than just new Date ( ) .getTime ( ) .I see the following on their github codebase.Can someone please explain what 's going on here ?
// A ( possibly faster ) way to get the current timestamp as an integer._.now = Date.now || function ( ) { return new Date ( ) .getTime ( ) ; } ;
How is Underscrore 's now method is faster ?
JS
So I 'm writing a game with JavaScript , and the biggest problem with that is that whoever is playing it who might have a decent knowledge of JS could open up my source code , figure out how it works , then plug a game.score = 100000000000000 ; into the console . However , it seems that aside from obfuscating the scrip...
( function ( ) { game_start = function ( ) { //etc } //etc } ) ( ) ;
Preventing code from being executed by the user
JS
I have the following function in JavaScript and when running it through JSLint , it yelled at me , as I call it.Specifically about the inline assignment expression in the while loop . I figured the double parentheses was the standard way of saying , `` I 'm expecting the returned value from the assignment expression to...
function getPos ( event , element ) { var x = event.clientX , y = event.clientY , currentElement = element ; do { x -= currentElement.offsetLeft - currentElement.scrollLeft ; y -= currentElement.offsetTop - currentElement.scrollTop ; } while ( ( currentElement = currentElement.offsetParent ) ) ; return { x : x , y : y ...
What 's the standard format for assignment expressions ?
JS
I have a table . For certain elements , I want to make an effect such that when we mouseover ( or click on ) an element , a text appears next to it , and the text could have several lines and some lines can be clickable.For example , in the table made by the following code , when we mouseover 30 , a text appearsJSBinHo...
< table style= '' width:100 % '' > < tr > < th > First Name < /th > < th > Points < /th > < /tr > < tr > < td > Jill < /td > < td > < span title= '' monday : 10 ; tuesday : 10 ; wednesday : 10 '' > 30 < /span > < /td > < /tr > < /table >
Make appear a text with several clickable lines
JS
For some reason , the manipulated doubleArray below is not shown in the console . Any variables that I declare after the for loop wo n't show to the console on both cases . Consider that in the first algorithm , there is only one for loop with x being incremented everytime . Whereas , in the second algorithm , it 's a ...
var isDuplicate = function ( ) { var helloWorld = [ 1,2,3,4,3 ] ; var doubleValue = [ ] ; var x = 0 ; for ( i = 0 ; i < helloWorld.length ; i++ ) { x = x + 1 ; if ( helloWorld [ i ] === helloWorld [ x ] & & i ! == x ) { doubleValue.push ( helloWorld [ i ] ) console.log ( helloWorld [ i ] ) ; } else { continue ; } } con...
Push duplicate items into a separate array in Javascript with for loop ?
JS
i have some problem which i ca n't figure out . so i have a div with background image . and i want to make clickable some point of this background image . It 's okey i can make this with adding to some div width z-index and make it clickable and positioning this with position : absolute e.g , but how i can keep this cl...
< div class= '' a '' > < /div > < div class= '' b '' > < a class= '' clickablePoint '' href= '' # '' > < /a > < /div >
How calculate div background image size on resize window
JS
My JSFiddle is here : https : //jsfiddle.net/h2kf5ztq/I 've largely tried to reproduce balexand 's answer from : How to enable bootstrap tooltip on disabled button ? including , importantly , the CSS : But for some reason , my disabled button does n't have a tooltip.How do I enable the tooltip ?
.tooltip-wrapper { display : inline-block ; /* display : block works as well */ margin : 50px ; /* make some space so the tooltip is visible */ } .tooltip-wrapper .btn [ disabled ] { /* do n't let button block mouse events from reaching wrapper */ pointer-events : none ; } .tooltip-wrapper.disabled { /* OPTIONAL pointe...
In Bootstrap , why does n't my disabled button have a tooltip ?
JS
When i use Array.fill to fill a multidimensional array , i get a weird behaviour when pushing to one of the arrays :
var arr = Array ( 2 ) .fill ( [ ] ) ; arr [ 0 ] .push ( 5 ) ; console.log ( arr ) ; //= > prints [ [ 5 ] , [ 5 ] ]
Weird behaviour in Array.fill
JS
I just want to practice Javascript , so I try this easy code.In my expected that the output should be whole list.When I use this code I only can get the output is I did not know what happened on it , and where was
[ 5 , 9 , 17 , 14 , 4 , 19 , 11 , 8 , 13 , 10 , 18 , 15 , 16 , 20 ] [ 1,0,2,3,6,7,12 ... ] var li = [ 5,9,17,14,1,0,4,19,11,6,8,13,10,2,18,15,16,3,12,7,20 ] var length = li.length ; var x = [ ] ; for ( var i = 0 ; i < length ; i++ ) { if ( ! ( li [ i ] in x ) ) { x.push ( li [ i ] ) ; } ; } console.log ( x ) ;
How to print whole list in for loop ?
JS
I have a HTML like this where inner is the child div and outer is the parent div . What I have to achieve : activate that div which has mouse over it.I have called the hover function of the jQuery and it is helping me to append and remove the active class . The problem : when I move the cursor upto innerchild div , it ...
$ ( 'div ' ) .hover ( function ( ) { $ ( 'div ' ) .removeClass ( 'activeHover ' ) ; $ ( this ) .addClass ( 'activeHover ' ) ; } , function ( ) { $ ( this ) .removeClass ( 'activeHover ' ) ; } ) ; .outer { background-color : # aeaeae ; height : 200px ; width : 200px ; float : left ; } .inner { margin : 50px ; background...
Parent child Hover not working as expected
JS
I am making a parser of sorts in javascript that takes a mathematical expression given to the script as a string , and evaluates it and does some other things with it . If the users want to use builtin Javascript mathematical functions , they have to enter the following string e.g . `` 1 + Math.log ( x ) '' . That beco...
input = input.replace ( / ( E|PI|SQRT2|SQRT1_2|LN2|LN10|LOG2E|LOG10E ) /g , `` Math. $ 1 '' ) ; ^ ( ? ! Math\ . ) ( log2|log|exp|abs )
Regex replace everything not starting with multiple times in line
JS
I have a div who 's height is set to a pixel height with CSS . It 's property overflow is set to hidden . It 's contents are greater in size than the set height . How do I get the height of the div 's content ( all content in total ; that is to say what would the height be if it was set to auto ) ? would var_representi...
div { height:100px ; overflow : hidden ; } < div > < p > Lorem ipsum dolor sit amet , consectetur adipiscing elit . Aenean et neque eget mi aliquam malesuada . Vivamus purus augue , vulputate vel mi nec , tincidunt porta libero . Pellentesque scelerisque vulputate auctor . Integer nec tincidunt sapien . Pellentesque qu...
Get height of an element 's content
JS
On book Eloquent JavaScript chapter 9 : Regular Expressions under Section `` Parsing an INI File '' there 's an example which includes a regular expression I do n't catch at all . The author is trying to parse next content : On the rules for this format state that Blank lines and lines starting with semicolons are igno...
searchengine=http : //www.google.com/search ? q= $ 1spitefulness=9.7 ; comments are preceded by a semicolon ... ; each section concerns an individual enemy [ larry ] fullname=Larry Doetype=kindergarten bullywebsite=http : //www.geocities.com/CapeCanaveral/11451 [ gargamel ] fullname=Gargameltype=evil sorcereroutputdir=...
What 's the difference between this two regular expressions ? ( Understanding ? Quantifier )
JS
I 'm currently building a number heavy app in Knockout . In my app there are three types of numbers : percentages , decimals and large numbers and I have custom binding handlers for each type.For the inputs I 've also created a number validation bindingHandler that reads each keypress to ensure that it 's a number bein...
< input data-bind= '' number : testdata , percentage : testdata '' >
Knockout share a binding handler
JS
Ive been learning how to use JSDoc with my projects , I mostly understand how to use it with the exception of 1 or two things . One of these things being documenting event listeners.Ive seen the documentation on the @ listens , but the explanation/example they give is not making sense to me . Heres a link to the page :...
document.getElementById ( 'some_element ' ) .addEventListener ( 'mousedown ' , function ( ) { // Some code } ) ;
JSDoc documenting event listeners properly
JS
I have been trying to search this , but have n't even found anyone with the same problem.For my assignment , I had to write a javascript code that would read all the text from the external page ( from the same directory though ) , but that 's not the problem . The problem appeared when I have created a test html file w...
< ! DOCTYPE html > < html lang= '' en '' > < head > < meta charset= '' UTF-8 '' > < title > test < /title > < /head > < body > < p > Just a random text. < /p > < h1 > More of a random text < /h1 > < p > And again , just testing the program. < /p > < /body > < /html > var externalPage ; var words = [ ] ; var j = 0 ; fun...
Unexpected hidden div appears in html file
JS
I just stumbled upon http : //www.newego.de/ and would like to know how the `` image slide effekt '' they are using on the initial page is done.When you scroll up the background image changes and after you went through all their `` intro/welcome '' -page slides you are guided to the main website content.I tried replica...
$ ( window ) .bind ( 'mousewheel DOMMouseScroll ' , function ( event ) { if ( event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0 ) { console.log ( 'scrolling down ' ) ; } else { console.log ( 'scrolling up ' ) ; $ ( '.s1 ' ) .slideUp ( 'slow ' ) ; } } ) ; * { margin : 0 ; padding : 0 } # menubar { wid...
How do I achieve a fully working image scrolling effect like in this example ?
JS
Beginner at both JSON and javascript . I need a way to return the key subAttributeOne it self from a list of object instead of his value.Following is example of a list , I have tried following , it returns value but the result I need is subAttributeOne
var list = [ { attribute1 : `` value '' , attribute2 : [ { subAttributeOne : '' value '' , subAttributeTwo : '' value '' } , { } ] } , //other objects { .. } ] list [ 0 ] .attribute2 [ 1 ] .subAttributeOne
how to get json objects attribute using javascript
JS
I am looking at the code to find out whether an object is an array on not , and I came across this answer.The code is working fine , but I am not able to understand how it is performing a comparison with [ object Array ] I tried to get the typeof Array , but it 's throwing an error . So I am confused with this code '' ...
if ( Object.prototype.toString.call ( someVar ) === ' [ object Array ] ' ) {
How toString ( ) .call ( ) on object prototype is fetching the type of Array
JS
I 'd like to enable/disable a button based on a datepicker , and I have a setup for a check like this : The check works good upwards , and enables the button when from date is lower , however ! If you log the values to the console be button is disabled because the init value is false , not because the check works.The t...
public dateChanged = false ; public availableFromDate : Date ; public availableToDate : Date ; initDatepickers ( ) { const currentDay = new Date ( ) ; this.availableFromDate = currentDay ; this.availableToDate = currentDay ; } private dateCheck ( ) { if ( ( this.availableFromDate > this.availableToDate ) || ( this.avai...
Why does two JS date Objects instantianted differently ?
JS
React 16.8 ( Using classes not hooks ) consider the following if statement in a function thats called onClickWhat I am trying to do is wait a second before posting the fight data if you have won the fight , the time out piece works . But as you can see I am updating the state to disable the button.What I was thinking o...
if ( this.state.opponentIsDead ) { this.setState ( { disableAttack : 'disabled ' , } , ( ) = > { this.timer = setTimeout ( ( ) = > { this.props.postFightData ( { train_exp : 100 , drop_chance : this.state.monster.drop_chance , gold_rush_chance : this.state.monster.gold_rush_chance , gold_drop : this.state.monster.gold_...
How to wait after setting the state in react
JS
I have 2 methods that I 'd like to use as chainable methods . Other methods may be chained to further modify text.left returns X characters from the left.right returns X characters from the right.Currently I can do this : What I want to do is this.Basically I want to return the results after the last chained method wit...
var txt = `` hello '' ; S $ ( txt ) .left ( 4 ) .right ( 2 ) .val //returns `` ll '' var txt = `` hello '' ; S $ ( txt ) .left ( 4 ) .right ( 2 ) //returns `` ll '' ( function ( global ) { var jInit = function ( text ) { this.text = text ; this.val = text ; } var jIn = function ( text ) { return new jInit ( text ) ; } ...
JavaScript Chainable Method Delimma
JS
I am trying to track PDFs that are dynamically created through a Wordpress backend . This is what I have so far , So basically , I am trying to make it look like in Google Analytics tracking , if one file is named PDF2015 and another is PDF14 , it would show up like that in the backend . Tough part is that they are bei...
< a class= '' download '' onClick= '' _gaq.push ( [ '_trackEvent ' , ' < ? php echo $ file [ 'name ' ] ; ? > ' , 'Download ' , 'Test ' ] ) ; '' href= '' < ? php echo $ file [ 'url ' ] ; ? > '' > Download < ? php echo strtoupper ( $ file_extension [ 0 ] ) ; ? > < /a > < a class= '' download '' href= '' < ? php echo $ fi...
Tracking PDFs generated by Wordpress backend with Google Analytics
JS
In javascript we can use module as singleton.I want to use it to be the configure of my module . Is there any risk ? It will always be a singleton in every module system ?
//a.jsexport default { str : 'aaa ' } //b.jsimport singleton from ' a.js'singleton.str='bbb'//c.jsimport singleton from ' a.js'singleton.str='ccc '
Use module as singleton
JS
I want to programatically alter route parameters before $ resource constructs the url . I can not use angular 's http interceptor to do this , since the route is already concatenated at that point.Given an Assortment.model.js ... and some controller.jsHow can I enforce a hook that will always convert { model : `` user ...
module.exports = function ( $ resource ) { return $ resource ( `` '' , { } , { get : { url : `` /assortment/ : model/ : id '' , method : `` GET '' , params : { id : `` @ id '' , model : `` @ model '' } // < this needs to be uppercase } } ) ; } ; [ `` Supplier '' , function ( Supplier ) { Supplier.Assortment.get ( { id ...
Run a hook before $ resource constructs the url ?
JS
I have a function that draws a tree-fractal in a canvas : I 'm trying to randomize the fractal a bit to make it look more organic . I tried this : For some reason this seems to be biased torwards the value 0 . The tree leans torwards the right . I do n't understand why .
var elem = document.getElementById ( 'canvas ' ) ; var context = elem.getContext ( '2d ' ) ; context.fillStyle = ' # 000 ' ; context.lineWidth = 1 ; var depth = 9 ; function drawLine ( x1 , y1 , x2 , y2 , brightness ) { context.moveTo ( x1 , y1 ) ; context.lineTo ( x2 , y2 ) ; } function drawTree ( x1 , y1 , angle , de...
Randomizing an angle ?
JS
Let 's say I have the following string : `` Stackoverflow '' , and I want to insert a space between every third number like this : `` S tac kov erf low '' starting from the end . Can this be done with regexes ? I have done it the following way with a for-loop now : Can I shorten this is some way ?
var splitChars = ( inputString : string ) = > { let ret = [ ] ; let counter = 0 ; for ( let i = inputString.length ; i > = 0 ; i -- ) { if ( counter < 4 ) ret.unshift ( inputString.charAt ( i ) ) ; if ( counter > 3 ) { ret.unshift ( `` `` ) ; counter = 0 ; ret.unshift ( inputString.charAt ( i ) ) ; counter ++ ; } count...
Javascript insert space at nth position in string
JS
I find that using the lifecycle method componentWillMount to setup initial state ... ... is slightly simpler than using the constructor . Namely because when you use the constructor you have to call super ( ) .Not only that but if your component is passed props and/or state then you have to manually pass those through ...
componentWillMount ( ) { this.state = { comments : [ ] } ; } constructor ( ) { super ( ) ; this.state = { comments : [ ] } ; } constructor ( props , state ) { super ( props , state ) ; ... }
Is there a reason people prefer using the constructor of a React component instead of componentWillMount ?
JS
Swap two numbersC++ : PHP : Javascript : Why ? Looks like all variables initialized before all expression executed ...
int a = 3 ; int b = 5 ; a^=b^=a^=b ; printf ( `` % d , % d\n '' , a , b ) ; //5 , 3 $ a = 3 ; $ b = 5 ; $ a^= $ b^= $ a^= $ b ; echo `` $ a , $ b\n '' ; //5 , 3 > a=3 ; b=5 ; a^=b^=a^=b ; [ a , b ] [ 0 , 3 ]
Strange javascript behaviour ( assignments )
JS
In Chrome version ^72 if I run the following JavaScript there are no errors.So the line of code is interpreted as an expression statement , unexpectedly.But if I run the same code with a semi-colon at the end it runs as expected.This is expected since the initial { tells the JavaScript engine that it is a code block un...
{ prop : p } = { prop : 'prop ' } > > { prop : 'prop ' } { prop : p } = { prop : 'prop ' } ; > > Uncaught SyntaxError : Unexpected token =
Why is this JavaScript not interpreted as a code block when semi-colon is used ?
JS
I have a nice challenge for those who like regex ; like me . Unfortunately , I can not figure this one out.This regex is a reverse match . I need to match everything but a proper amount ; like : These types need to NOT MATCH : 0,000.0012314345.724234.5434435,0034545,43 These types need to MATCH : .00,871e3,67 So everyt...
( [ ^0-9 ] + ( [ ^\. , ] { 0,1 } ) + [ ^0-9 ] { 0,2 } )
Regex everything but number with two decimals
JS
I noticed in several MDN Array method shims , such as this one on line 7 , that they use the following syntax : Where this is an array . Not only does it not hint in my validator , I ’ m also clueless as to what it does.Can anyone shed a light ?
var t = Object ( this ) ;
What does Object ( this ) do ?
JS
Given this code : Clicking the button will alert `` blah '' . Why does the id attribute become a variable visible within the scope of the onclick handler ? Another example : Here we see that style refers to a CSSStyleDeclaration object , rather than the string value of the attribute . This is similar to what we 'd get ...
< button id= '' blah '' onclick= '' alert ( id ) '' > Click me < /button > < button style= '' font-size:200 % '' onclick= '' console.log ( style ) '' > Click me < /button >
Why do an element 's attributes appear in the scope of an inline function ?
JS
I have a page set up with a back to top link ( in an entire bar ) slides down at the top of the page , only on scroll up.I 'm a beginner with Javascript , so I have cobbled something together , that does work ( it shows on scroll up , unless we 're 500px from the top , hides on scroll down ) , and it uses some code I g...
// Hide Header on on scroll downvar didScroll ; var lastScrollTop = 0 ; var delta = 5 ; var subMenu = $ ( ' # subMenu ' ) .offset ( ) .top ; $ ( window ) .scroll ( function ( event ) { didScroll = true ; } ) ; setInterval ( function ( ) { if ( didScroll ) { hasScrolled ( ) ; didScroll = false ; } } , 250 ) ; function h...
Javascript syntax help for a back to top link that appears only on scroll up
JS
Consider the following regex : This matches a single character at the start of the string , if possible : However , wrapping the . in a lookahead causes it to stop working : The value of undefined indicates that the group did n't match , rather than having matched an empty string . But I do n't understand how the looka...
( ^. ) ? > > 'ab'.match ( / ( ^ . ) ? / ) Array [ `` a '' , `` a '' ] > > 'ab'.match ( / ( ^ ( ? = . ) ) ? / ) Array [ `` '' , undefined ] > > 'ab'.match ( / ( a ( ? = . ) ) ? / ) Array [ `` a '' , `` a '' ] > > 'ab'.match ( / ( ^ ( ? = . ) ) / ) Array [ `` '' , `` '' ]
Why does a lookahead in an optional 0-width capture group prevent the group from matching ?
JS
I am trying to dynamically append an HTML-snippet to an existing Element with .append . Somehow , the HTML String which was created by the script is not appended to the element . The element which is appended to is not hooked into the DOM at the moment when the snippet is appended . All of it is encapsulated in a JavaS...
append_content = function ( ) { var elem = $ ( ' < li > < div > some text < /div > < /li > ' ) ; var somecontent = get_content ( ) ; // returns a string : ' < div > xx < /div > ' elem.append ( ' < div > bleh1 < /div > ' ) ; elem.append ( somecontent ) ; elem.append ( ' < div > bleh2 < /div > ' ) ; console.log ( elem ) ...
Adding generated content to jQuery object which is not bound to the DOM fails
JS
The following evaluate to true : Obviously , but so do the following : So can someone explain clearly why he following evaluates false ?
new Number ( 2 ) == 2new String ( `` 2 '' ) == `` 2 '' `` 2 '' == 2new Number ( 2 ) == `` 2 '' new String ( `` 2 '' ) == 2 new Number ( 2 ) == new String ( `` 2 '' )
Why does new Number ( 2 ) ! = new String ( `` 2 '' ) in JavaScript
JS
Consider the following code : Code above works fine in case I need to call an action foo or bar inside action test . However action test itself supposed to be a callable function . I thought it would be cool if JavaScript would let me create something like this ( see below ) but , as expected , says : TypeError : actio...
function test ( ) { this.foo = function ( ) { console.log ( 'foo ' ) ; return ; } this.bar = function ( ) { console.log ( 'bar ' ) ; return ; } } var action = new test ( ) ; action.foo ( ) ; //prints 'foo ' function test ( ) { this.foo = function ( ) { console.log ( 'foo ' ) ; return ; } this.bar = function ( ) { conso...
Define a function with nested functions and default function
JS
http : //jsfiddle.net/garnwraly/sfrwU/2/given HTML of onlyand this scriptwhy is $ ( e.currentTarget ) .parent ( ) .is ( 'li : first ' ) false ?
< li > < button id= '' bam '' > click < /button > < /li > $ ( 'body ' ) .on ( 'click ' , 'button ' , function ( e ) { //console.log ( e.currentTarget == $ ( 'button ' ) [ 0 ] ) ; //true ; //console.log ( $ ( 'li ' ) .is ( 'li : first ' ) ) ; //true console.log ( $ ( e.currentTarget ) .parent ( ) .is ( 'li : first ' ) )...
is ( ' : first ' ) returns different ( wrong ? ) results for what should be the same element . jsFiddle inside
JS
I have build a small bootstrap 3 thumbnails text and img manipulation , now I have a question on how to make this active when page load , to be specific I would like that # anime1 be active when page loads . Check out this manipulation example . You will see that I have a bunch of thumbnails just displaying there , but...
$ ( function ( ) { $ ( ' # anime1 ' ) .click ( function ( ) { $ ( '.column ' ) .each ( function ( ) { $ ( this ) .hide ( 500 ) ; } ) ; $ ( '.columns ' ) .each ( function ( ) { $ ( this ) .show ( 500 ) ; $ ( ' # col1 img ' ) .attr ( 'src ' , 'img/lazy1.png ' ) .prepend ( 'background-image ' , 'url ( img/lazy.png ) ' ) ;...
Activate jQuery img and text manipulation on page load
JS
I 'm trying to connect two points with a line while moving one of them . I 'm really lost in finding the real x , y position of anything on a document ... I 've read about how paddings , element sizes and all these things can mess up this process , but none of the tutorials or example codes worked . I would really appr...
var node = document.querySelector ( `` # node '' ) ; var startNode = document.querySelector ( `` # startnode '' ) ; var container = document.querySelector ( `` # container '' ) ; container.addEventListener ( `` click '' , SetNodePosition , false ) ; function SetNodePosition ( e ) { startX = getPosition ( startNode ) .x...
How to find position of HTML elements in JavaScript ?
JS
I know this is something easy that is just eluding me.Anyway , I have a simple function that loops through a series of six images and text and hides and shows them based on which one is visible.Issue I 'm having is that when it gets to the last image , it should just start over with the first but instead it goes back t...
< script type= '' text/javascript '' > setInterval ( 'testAnimation ( ) ' , 5 * 1000 ) ; show = 0 ; function testAnimation ( ) { $ ( `` # headerImage '' + show ) .fadeOut ( ) ; $ ( `` # headerText '' + show ) .fadeOut ( ) ; if ( show == 5 ) { show = 0 ; } else { show++ ; } $ ( `` # headerImage '' + show ) .fadeIn ( ) ;...
Javascript looping issue
JS
I 'm trying to return all the items which broke a relationship in the following array : As you can see each item is linked each other using the property bound_id , if a property broke a relation like : the following result is returned : I 'm using the following code : I want to include is to insert only the relationshi...
[ { id : `` 1 '' , option : { bound_id : `` 2 '' } } , { id : `` 2 '' , option : { bound_id : `` 12 '' } } , { id : `` 12 '' , option : { bound_id : `` 2 '' } } ] [ { id : `` 1 '' , option : { bound_id : null } } , { id : `` 2 '' , option : { bound_id : `` 12 '' } } , { id : `` 12 '' , option : { bound_id : `` 2 '' } }...
How to set condition when using filter ?
JS
This question is related to performance.If I use a selector like the followingOr should I write the statement like this ? I 'm not sure if jQuery is smart enough to execute this statement using the ID first or if it operates exactly like CSS and reads right to left . It 's not such a big deal using tags but when you ru...
$ ( ' # myID a ' ) // Does this find # myID and filter by a ? $ ( ' # myID ' ) .find ( ' a ' ) $ ( ' # myID .myClass ' )
Will jQuery search for the ID before filtering other parameters in the selector ?
JS
I 'm trying to copy a section of a webpage when a link is clicked so that the section is recreated underneath the previous section just like how this works in this image as example- I 'm doing this on google apps script and here is my codecode.gsHTML.html
function doGet ( e ) { return HtmlService.createHtmlOutputFromFile ( 'HTML ' ) .setSandboxMode ( HtmlService.SandboxMode.IFRAME ) ; } < html > < head > < base target= '' _top '' > < style type= '' text/css '' > .contentBackground { background-color : # D8D8D8 ; clear : left ; width : 60 % ; margin : auto ; height : 200...
How to copy this section of a webpage when a link is clicked ?
JS
I 've come up against this issue in multiple contexts and languages and I always been able to work around it but I 'd like to finally figure out a proper pattern to handle this . It comes from joining SQL tables . Usually I would make two calls , one for items and one for comments but I know there 's a way to get it al...
[ { itemId : 1 , comments : { commentId : 1 } } , { itemId : 1 , comments : { commentId : 2 } } , { itemId : 2 , comments : { commentId : 3 } } ] [ { itemId : 1 , comments : [ { commentId : 1 } , { commentId : 2 } ] } , { itemId : 2 , comments : [ { commentId : 3 } ] } ]
Flattening an array of objects into another array of objects using javascript
JS
I do n't understand the 'Primitives will be wrapped to objects ' part of example.https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign # Primitives_will_be_wrapped_to_objectsThe example shows that the primitives will be wrapped , but the result is an empty object.Is the result...
var v1 = true ; var v2 = 10 ; var v3 = Symbol ( 'foo ' ) ; console.log ( Object.assign ( { } , v1 , v2 , v3 ) ) ; //ouput : { }
When I use primitives for Object.assign ( ) , the results are presented as empty objects
JS
I 'm learning a react course online . When I try to display the list of items from an array using map to display in a child component , I keep getting `` can not read property map of undefined.Error is thrown while fetching data from users
import React , { Component } from `` react '' ; import ReactDOM from `` react-dom '' ; let userList = [ { name : `` John '' , age : 24 , place : `` India '' } , { name : `` Henry '' , age : 24 , place : `` India '' } , { name : `` Ulrich '' , age : 24 , place : `` India '' } ] ; const AppChild = ( { name , age , place ...
Property 'map ' of undefined in React
JS
The jQuery source is wrapped in a closure , like this : I do n't understand why either of these parameters are needed . Since window is a global variable , why does it need to be passed in ? What 's the purpose of passing in a global parameter and accessing it inside the closure with the same name ? What 's the undefin...
( function ( window , undefined ) { //awesome jQuery library code in here } ) ( window ) ;
Why are these two parameters in the jQuery source for ?
JS
I came across in a seemingly reputable source a strange date manipulation that I do n't understand . This is part of the samples in supporting documentation for a popular UI framework : Now line by line var startDate = start.value ( ) ; this lines returns Date object and saves it in startDate variable . Fine here , no ...
var startDate = start.value ( ) ; // returns Date objectstartDate = new Date ( startDate ) ; startDate.setDate ( startDate.getDate ( ) ) ;
Javascript strange date manipulation
JS
This code is about fetching data from MongoDB and changing '_id ' element to 'id element.But I found object array is not changed.but this code work as what I want } ) ; I think it is related with deep and shallow copy . But I do n't know what cause it exactly.Thanks
router.get ( '/loadList ' , ( req , res ) = > { Post.find ( { } , ( err , list ) = > { //fetching data to list if ( err ) { return res.json ( { success : false } ) ; } else { let new_list ; //change _id to id new_list = list.map ( ( obj ) = > { obj.id = obj._id ; delete obj._id ; return obj ; } ) ; console.log ( new_li...
javascript object array is not changed
JS
I 'm trying to achieve a jQuery effect like : http : //jsfiddle.net/Qcghe/1/I want to animate the colour of the dots in the following order : white , white , white ( initial state ) blue , white , whiteblue , red , whiteblue , red , greenwhite , red , greenblue , white , greenblue , red , white…and back to the initial ...
$ ( document ) .ready ( function ( ) { setInterval ( function ( ) { $ ( 'small : nth-of-type ( 1 ) ' ) .animate ( { color : ' # F7B903 ' } , 750 ) .animate ( { color : ' # FFF ' } , 1000 ) ; } , 1000 ) ; setInterval ( function ( ) { $ ( 'small : nth-of-type ( 2 ) ' ) .animate ( { color : ' # 5BB6FD ' } , 750 ) .animate...
jQuery color style alternating
JS
I have this code and when I put the anchor ( arrow img ) outside , .MultiCarousel div it does n't work . I did n't write the code but I think I should change something in JavaScript . I want the anchor outside the container div but with the same functionality . I am not very familiar with JavaScript so I do n't know wh...
$ ( document ) .ready ( function ( ) { var itemsMainDiv = ( '.MultiCarousel ' ) ; var itemsDiv = ( '.MultiCarousel-inner ' ) ; var itemWidth = `` '' ; $ ( '.leftLst , .rightLst ' ) .click ( function ( ) { var condition = $ ( this ) .hasClass ( `` leftLst '' ) ; if ( condition ) click ( 0 , this ) ; else click ( 1 , thi...
Buttons do n't work when I place them outside the carousel
JS
I 'm looking for a regular expression pattern to match a string that contains all of a list of required characters.For example , if my requirements are `` abc '' : Match : `` abacus '' , `` back '' , `` cab '' .Do n't match : `` abs '' , `` car '' , `` banana '' .So far , I 've come up with these ( non-regex ) methods ...
function testA ( requiredChars , checkString ) { return requiredChars.split ( `` ) .every ( char = > checkString.indexOf ( char ) ! == -1 ) } function testB ( requiredChars , checkString ) { for ( let char of requiredChars.split ( `` ) ) { if ( checkString.indexOf ( char ) == -1 ) return false } return true } tests = [...
JavaScript : Match string with all required characters
JS
I 've been trying to convert the following from Python to node.js . It 's a simply program that uses regex to check if an IP address is Public or Private : I implemented it in Javascript like this : Which gives me the following output : It seems to me like it works ( not even sure tbh ) . The two IPs that should be pub...
import redef is_private_ip ( ip ) : `` '' '' Returns ` True ` if the ` ip ` parameter is a private network address. `` '' '' c = re.compile ( ' ( ^127\.0\.0\.1 ) | ( ^10\. ) | ( ^172\.1 [ 6-9 ] \. ) | ( ^172\.2 [ 0-9 ] \. ) | ( ^172\.3 [ 0-1 ] \. ) | ( ^192\.168\ . ) ' ) if c.match ( ip ) : return True return Falseprin...
Contents of a RegExp match
JS
I 'm trying to filter data from the response and remove duplicate items and push the data into an array , my api response goes as below : From the above response , if `` booking_id '' exist in object and `` booking_id._id '' is same then , I need to filter and push only unique objects to array.I need a response as belo...
{ `` _id '' : '' 0 '' , `` yacht_id '' : '' 200 '' , `` promo_id '' : '' 300 '' , `` blocked_thru '' : '' promotions '' , `` dates '' : '' 2017-08-23T00:00:00.000Z '' , } , { `` _id '' : '' 1 '' , `` booking_id '' : { `` _id '' : '' 100 '' , `` booking_id '' : '' BK163041494 '' , } , `` blocked_thru '' : '' booked '' ,...
How to filter different keys in a array and get unique result in angular js
JS
I have a list of questions with answer options as radio button field . I 'm getting these questions and answers from JSON file.so am iterating over it on HTML and assigning values to formControlName dynamically . My problem is how to validate while iterating over control values ? this gives me an error . How to do it i...
*ngIf= '' cricketForm.control.get ( 'ques { { i } } ' ) .invalid '' *ngIf= '' cricketForm.control.get ( 'ques { { i } } ' ) .invalid '' < form [ formGroup ] = '' cricketForm '' > < div *ngFor = `` let user of userJson ; let i =index `` > < div class= '' label1 '' for= '' NameId '' > { { user.question } } < /div > < mat...
Angular form validation , access form control while iterating over it on HTML
JS
I have a combobox in which one can select a certain time span , e.g . : It always transmits the number of minutes to the server , but the user would n't understand what `` 10080 '' means ( before you try to calculate : it 's a week ) .A new requirement is that the user should be able to type arbitrary values into that ...
5 minutes15 minutes1 hour2 hours1 day2 days1 week2 weeks rawToValue : function ( rawValue ) { console.log ( 'rawToValue ' ) ; console.log ( rawValue ) ; return this.parse ( rawValue ) || rawValue || null ; } , valueToRaw : function ( value ) { console.log ( 'valueToRaw ' ) ; console.log ( value ) ; return this.format (...
A combobox that auto-corrects the value
JS
Why do some people write this : instead ofI have checked the resource with ? ver=2.70 or without ? ver=2.70 and I did not see any differences .
shop/js/uds-jsonp.js ? ver=2.70 shop/js/uds-jsonp.js
Why use `` ? ver=2.70 '' in css or script route ?
JS
Example in coffeescriptIs there anyway to detect that APP.stuff has 2 bindings to its name property ?
window.APP = Ember.Application.create ( ) APP.stuff = Ember.Object.create ( name : `` The Name '' ) APP.things = Ember.Object.create ( nameBinding : `` APP.stuff.name '' ) APP.gizmos = Ember.Object.create ( nameBinding : `` APP.stuff.name '' )
Is there a way to list all the Bindings to an Ember.Object ?
JS
I have a datepicker on my angularJS WCFrest projecti get the data using but the data that acquired is too complex when i get the data Fri Dec 16 2016 00:00:00 GMT+07 ( SE Asia Standard Time ) i just want to get the value like on the date picker interface 12/16/2016this is my controller.jsis there any way to format the ...
< div class= '' col-md-4 '' > < input id= '' txtOldDate '' type= '' date '' class= '' datepicker '' ng-model= '' oldDate '' / > < /div > $ scope.SearchApproval = function ( employeeID , oldDate , newDate , departemen , approver ) { var promiseGet = GetApproval.GetApprovalData ( $ scope.employeeID , $ scope.oldDate , $ ...
Date Time format too complex when bind the value , AngularJS
JS
This code : The question is : Why these version get the same time for smaller value of i ? If I cut an single zero from i ; all versions need 2.2 seconds . ( tested even after JIT optimizations - only in V8 ) It seems logical that the third version should be always faster but it is faster only for very high values.It '...
var i = 10000000000 ; do { i -- ; } while ( i ! == 0 ) ; //Result : 38 second.var i = 10000000000 ; do { } while ( i -- ! == 0 ) ; //Result : 27 second.// ( same result with while ( i -- ) var i = 10000000000 ; do { } while ( i -- | 0 ) ; //Result : 13.5 second .
Why does this code behaves different at different values
JS
Given an object definition : At enumeration time , Chrome appears to respect the order in which the attributes are defined : Yields : Does JavaScript and/or the JSON specify this level of order-preservation ? In either case , is it reliable ?
var o = { x :1 , y:2 , z : 3 , b : 4 , a : 5 , m : 6 , X : 7 } ; for ( var i in o ) { console.log ( i , o [ i ] ) ; } x 1y 2z 3b 4a 5m 6X 7
Does JavaScript and/or JSON require parsers enumerate attributes in definition order ?
JS
I was told that you must always declare functions in JavaScript . Is that true ? What is the advantage of it ? I usually assign functions to a variable as such : But supposedly this is wrong , something to do stack tracing . Can someone please explain ? I was told to do : Would it make sense if it 's assigned to an obj...
var foo = function ( ) { } ; var foo = function fooBar ( ) { } ; var Foo = { } ; Foo.Bar = function Bar ( ) { } ;
Why always declare functions in JavaScript ?
JS
I create a diagram with chart.js . This diagram has two lines . So it displays also two labels by default . But I need a configuration where one for example the red label should appear and the blue one should be hidden . The label not the line ! ! Thanks for your help
var config = { type : 'line ' , data : { labels : [ '16:30 ' , '17:30 ' , '18:30 ' , '19:30 ' , '20:30 ' ] , datasets : [ { label : 'High ' , backgroundColor : 'blue ' , borderColor : 'blue ' , data : [ 10.43 , 10.42 , 10.44 , 10.43 , 10.40 ] , fill : false , } , { label : 'low ' , fill : false , backgroundColor : 'red...
How to display only one label in a multi line char ?
JS
I want to learn the javascript reduce function . I have implemented the following using a different solution , but want to achieve the same through reduce.I have an alphabets array and names array.Using javascript reduce funtion , I want to map key value pair like , Key A should contain a list of fruits that start with...
alphabets : [ ' A ' , ' B ' , ' C ' , 'D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , 'M ' , ' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , 'S ' , 'T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' ] ; names : [ { name : 'Apple ' } , { name : 'Apricot ' } , { name : 'Avocados ' } , { name : 'Almond ' ...
JavaScript - How to Map a list of names to a specified key using reduce
JS
I am a beginner in JavaScript and I would like to simulate an exercise using HTML and JavaScript . Basically , I have two inputs that take 1 : the name of a product and 2 ) the quantity of this item . When user click on a button , the function that calculates the total amount for that item is executed . On this functio...
function calTotItemA ( ) { var item = document.getElementById ( `` itemName '' ) .value ; var itemQ = document.getElementById ( `` itemQuantity '' ) .value ; var itemTotal = 0 ; switch ( item ) { case `` eggs '' : this.itemTotal = 3.5 * itemQ ; break ; case `` milk '' : this.itemTotal = 4.5 * itemQ ; break ; } document...
Number assigned to a variable using Case Switch returning 0 instead of correct result
JS
What is the difference between these function calling styles ? And
onPress = { ( ) = > { this.myFunctions ( ) } } onPress = { this.myFunctions ( ) }
Difference between style of passing functions
JS
For example : Which one is faster ? Long loop first : Or short loop first : Or are there any advantages in either that I 'm not considering ? Or does it not matter at all ?
var longArray = [ 1 , 2 , 3 , 4 ] var shortArray = [ 2 , 3 ] for ( var i = 0 ; i < longArray.length ; i++ ) { for ( var j = 0 ; j < shortArray.length ; j++ ) { if ( longArray [ i ] === shortArray [ j ] ) { // do something } } } for ( var i = 0 ; i < shortArray.length ; i++ ) { for ( var j = 0 ; j < longArray.length ; j...
In a nested for loop , is there any advantage in starting with the longer loop ? Or vice versa ?
JS
I 'm making a small game in JavaScript . I 've created a small example js fiddle demo link . There are three situations as listed bellow : A : Outside of target object.B : Overlaping with target object 's border.C : Inside of target object.According to Have object detect if completely inside other object JavaScript , I...
< div class= '' main '' > < div class= '' target '' > < /div > < div class= '' obj '' > A < /div > < div style= '' top:15 % ; left:50 % ; '' class= '' obj '' > B < /div > < div style= '' top:25 % ; left:35 % ; '' class= '' obj '' > C < /div > < /div >
JavaScript : Detect if DOM element overlaping , inside or ouside with DOM element ?
JS
I have below array of objects.I need to get below outputI can get the top level field using thisBut not able to access the inner ones.Kindly help ... Thanks ! ! !
const array = [ { field1 : `` val1 '' , field2 : `` val2 '' , field3 : { field1 : `` val1 '' , field2 : `` val2 '' } } , { field1 : `` val1 '' , field2 : `` val2 '' , field3 : { field1 : `` val1 '' } } ] const output = [ { key : `` field1 '' , subkeys : [ ] } , { key : `` field2 '' , subkeys : [ ] } , { key : `` field3...
How to get keys and sub keys from the array of object ?
JS
Why is v1 so much slower than v2 ? v1 -- v2 -- I figured that since I 'm holding a reference to the new object in 'ref ' , that simply assigning that reference to an element in the array would be about as fast as assigning a literal value , but it turns out that assigning the reference is considerably slower . Can anyo...
var foo = function ( a , b , c ) { this.a=a ; this.b=b ; this.c=c ; } var pcs = new Array ( 32 ) ; for ( var n=32 ; n -- ; ) { ref = new foo ( 1,2,3 ) pcs [ n ] = ref ; //***** } var foo = function ( a , b , c ) { this.a=a ; this.b=b ; this.c=c ; } var pcs = new Array ( 32 ) ; for ( var n=32 ; n -- ; ) { ref = new foo ...
Performance issues with saving object reference to array
JS
While going through javascript course on codecademy.com , I 've become slightly confused.So first we 've been learning how to add method to a Class : Then we started the `` prototype '' . And there was this example : Both examples are giving the same result . Are these two examples are just two ways doing same thing ? ...
function Dog ( breed ) { this.breed = breed ; this.sayHello = function ( ) { console.log ( `` Hello this is a `` + this.breed + `` dog '' ) ; } } ; var someDog = new Dog ( `` golden retriever '' ) ; someDog.sayHello ( ) ; function Dog ( breed ) { this.breed = breed ; } ; Dog.prototype.sayHello = function ( ) { console....
What is the difference between ` this ` and ` prototype ` ? javascript oop
JS
I 'm using chartjs to display some data but I 'm in trouble with the Y axis visualization . I want at every point in the graph a value in the Y axis . Right now the Y axis display value in steps of 10.This is my actual yAxis configuration : This is the actual chart . I would like to display in the Y axis only the actua...
yAxes : [ { position : `` left '' , ticks : { source : '' data '' , } } ]
How to show Y axis ticks for every point in the graph