lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
How can I convert Javascript 's -0 ( number zero with the sign bit set rather than clear ) to a two character string ( `` -0 '' ) in the same way that console.log does before displaying it ?
x = -0 > > -0typeof ( x ) > > `` number '' x.toString ( ) > > `` 0 '' console.log ( x ) > > -0
Javascript . Correctly convert -0 to a string
JS
I use jQuery to add line in a table , with some input / select . I have a template line that is display : none , and for add a new line I duplicate this one and past it at the end of tbody of my table . Some code : CSS : PHTML : jQuery : With IE8 it work pretty well , the line is add correctly in the tbody and is corre...
.template { display : none ; } .regle { display : block ; } < table class='w100 ' cellspacing= ' 0 ' cellpadding= ' 0 ' id='listTable ' > < thead > < tr > < th > foo < /th > < th > bar < /th > < th > foobar < /th > < /tr > < /thead > < tbody > < tr class= '' template '' > < td > < ? php echo $ this- > form- > foo- > re...
appendTo does n't put my element where I want
JS
I 'm looking into the use cases for the good old void operator . One that I 've seen mentioned is for preventing arrow functions from `` leaking '' their result , because of the way they 're often written ( see fn0 in example below ) .So the argument is to use void to prevent such leaks in the cases you do n't actually...
function doSomething ( number ) { return number + 1 } const fn0 = ( ) = > doSomething ( 1 ) const fn1 = ( ) = > { doSomething ( 1 ) } const fn2 = ( ) = > void doSomething ( 1 ) console.log ( fn0 ( ) ) // 2console.log ( fn1 ( ) ) // undefinedconsole.log ( fn2 ( ) ) // undefined
Void in single expression arrow functions
JS
I have code below for a content cycle I have created with the help from some other Stack Overflow users . Is it possible to have the circular arrow fill up partially depending on what box your hovered on . Example : If the user hovers on box four ( the bottom box ) the circular arrow would fill up with a different colo...
.container .row { text-align : center ; position : relative ; } .row { position : relative ; } .one { display : inline-block ; background-color : # 1f497d ; width : 100px ; height : 50px ; border-width : 3px ; border-style : solid ; border-color : # ededed ; border-radius : 7px ; box-shadow : 0px 1px 5px # 888888 ; } ....
Partially fill object when hovering
JS
I have a string ( resultString ) that contains long html codes . These codes are grouped in 2 main DIVs , window and Popup . Now I want to retrieve the html content of window and popup DIVs separately and place them in 2 different strings ( stringWindow and stringPopup ) .Is there any simple way to do so in jQuery/java...
resultString = `` < div id=\ '' window\ '' > window content -- - long html codes < /div > < div id=\ '' PopUp\ '' > Popup content -- - long html codes < /div > '' stringWindow = `` < div id=\ '' window\ '' > window content -- - long html codes < /div > '' ; stringPopup = `` < div id=\ '' PopUp\ '' > Popup content -- - ...
Dividing a string in 2 parts and placing each part in a different new string
JS
Suppose , as an example , the following exact test.html document , saved in UTF-8 encoding : How can I determine in IE11 and Chrome latest what the browser decided to guess for a doctype , if any ? ( Note that the document above is merely an example , I 'm looking for a method to determine doctype as assumed by the bro...
< html > < head > < title > Test < /title > < /head > < body > Test document. < /body > < /html >
How to determine doctype if none was set in the document ?
JS
I have the following button : Now this calls a JavaScript function called assign_allThis works fine however when it is done executing the JavaScript it simply tries to load a page . Which is fairly odd ( its like if you click on an A tag ) As you can see below nothing in my javaScript indicates that it should reload / ...
< div class= '' form-group '' > < button onclick= '' assign_all ( ) '' class= '' btn btn-default '' > Vælg alle < /button > < /div > function assign_all ( ) { var info = [ ] ; var i = 0 ; $ ( '.user_list ' ) .each ( function ( ) { if ( $ ( this ) .hasClass ( 'show ' ) ) { info [ i ] = $ ( this ) .find ( '.user_id ' ) ....
HTML Button redirects pages
JS
I 'm looking for an efficient way to return unique values in objects inside an array . For example the next object : What I want to return is the following : So I want for each item inside the tags object a new object . After that , I want an array with all unique values over all the products . I do somewhat the same w...
{ `` products '' : [ { `` id '' : 1 , `` category '' : `` test1 '' , `` tags '' : { `` option '' : [ `` A '' , `` B '' ] } } , { `` id '' : 2 , `` category '' : `` test2 '' , `` tags '' : { `` option '' : [ `` B '' ] , `` type '' : [ `` A '' , `` B '' , `` C '' ] } } , { `` id '' : 3 , `` category '' : `` test1 '' , ``...
Loop over objects inside a list and return unique values
JS
From what I 've testedreturns 1 in ie83 in firefox , chrome , operaI was always prepared to handle differences in DOM manipulation , or Events model , but I 've thought that things like strings , regexps , etc . are well defined . Was I wrong ?
`` aba '' .split ( /a/ ) .length
Is there any standard which says if `` aba '' .split ( /a/ ) should return 1,2 , or 3 elements ?
JS
Wanting to get something straight here ... so I have 2 questionsThe function below creates a closure.Q : Which function is the closure , Foo or Bar ? I always thought the closure to be Foo , because it closes-over Bar once Bar is returned.Next ... Below is the definition of an anonymous function : Q : Is the inner-func...
function Foo ( message ) { var msg = message ; return function Bar ( ) { this.talk = function ( ) { alert ( msg ) ; } } } ; ( ) ( ) ; ( function ( ) { /* < -- Is this function also a closure ? */ } ) ( ) ;
Are these considered to be Javascript closures ?
JS
The output for this sample code is.01112131415161Why in Javascript these index of array is treated as a string ?
var arrayOfNumbers= [ 1,2,3,4,5,6,78 ] ; for ( var index in arrayOfNumbers ) { console.log ( index+1 ) ; }
Why is index of an Array a string in the below code ?
JS
So basically I 'm implementing the typical way to handle JavaScript calls in objc using window.location= '' myobj : mymethod : myarg : myotherarg '' , however , I 'm wondering if there is a way to apply an array of arguments to a method , similar to how you can in JavaScript.Typically I 've been doingI 'd prefer to do ...
- ( void ) mymethod : ( NSArray* ) arr { //method knows how many arguments it takes and what they mean at each index } - ( void ) mymethod : ( NSString* ) myarg myOtherArg : ( NSString* ) myotherarg { //do stuff } + ( void ) callMethod : ( NSString* ) selectorName withArgs : ( NSArray* ) args onObject : ( id ) obj { //...
Is there JavaScript apply like method in objective-c ?
JS
I stumbled upon code similar to this in modern JavaScript : Any modification is done outside of the computed property , as if there were none.I was expecting the computed property to still exist.Is there a way to preserve the computed property after a call to Object.assign ? Thanks .
let obj = { data : { number : 9 } , set prop ( p ) { this.data = p ; } , get prop ( ) { return this.data ; } } ; obj = Object.assign ( { } , obj , { data : { number : 2 } } ) ; console.log ( 'obj.data === obj.prop ' , obj.data === obj.prop ) ; console.log ( 'obj.data.number === obj.prop.number ' , obj.data.number === o...
Why is my computed property not effective after Object.assign ?
JS
I have a user who is getting the error I 'm confused how this can happen . Wo n't trying to access an undefined variable throw a reference error ? In what situation could it throw a type error ?
TypeError : a is undefined
How could an undefined variable throw a type error ?
JS
I guess I kind of know the differences between == and === in JavaScript , it is that == will do type coercion when compare but === will not . I understand the following code will be true : but when the code below is false ?
console.log ( true == `` 1 '' ) ; console.log ( true == `` true '' ) ;
type coercion in JavaScript
JS
I 'm just looking for ideas/suggestions here ; I 'm not asking for a full on solution ( although if you have one , I 'd be happy to look at it ) I 'm trying to find a way to only upload changes to text . It 's most likely going to be used as a cloud-based application running on jQuery and HTML , with a PHP server runni...
asdfghjklasdfghjkl asdfghjklXasdfghjkl
Find what has been changed and upload only changes
JS
I try to understand variable scope in Javascript . Here is what I am doing : The output is always 3 , and I understand that 's because i has been retained by reference . How do I localise i so it can log incremented value ? Thanks ! updateThanks guys for quick and decent responses . the solutions are indeed of help ! I...
< script > for ( var i = 0 ; i < 3 ; i++ ) { document.getElementById ( i ) .onclick = function ( ) { console.log ( i ) ; } } < /script > < script > for ( var i = 1 ; i < = 3 ; i++ ) { document.getElementById ( i ) .onclick = function ( ) { console.log ( logCall ( i ) ) ; } } function logCall ( i ) { return i ; } < /scr...
javascript : localise variables in block
JS
We have an array of arrays like this : There may be duplicate elements in each array and that 's fine.But I 'm after a proper solution to remove duplicate elements in each set comparing to lower sets ! So as we have a 0 in the first array and the last array , we should consider the 0 in last one a duplication and remov...
const arrays = [ [ 0 , 1 , 2 , 3 , 4 , 4 , 4 , 4 ] , [ 5 , 6 , 7 , 8 , 9 , 10 , 11 , 11 ] , [ 2 , 7 , 10 , 12 ] , [ 0 , 7 , 10 , 14 ] ] ; [ 0 , 1 , 2 , 3 , 4 , 4 , 4 , 4 ] , [ 5 , 6 , 7 , 8 , 9 , 10 , 11 , 11 ] , [ 12 ] , [ 14 ]
remove duplicate elements in proceeding arrays inside array of arrays
JS
Consider following example : br does not have $ x property any more , because when copying array , angular iterates with for ( ; ; ; ) which does not see custom properties ( if it iterated with for in then it would work ) .Which of following shall I do ? Create array like class and then assign property ; If it 's bug ,...
var ar = [ 4 , 2 , 3 ] ; ar. $ x = 'something ' ; var br = angular.copy ( ar ) ; console.dir ( br ) ;
angular.copy when array has custom property
JS
I am given an array of functions of length N , where every function has an asynchronous call and accepts a callback argument . The callback of function [ x ] is function [ x+1 ] , and function [ N-1 ] has no callback . Here 's an example of what I might be given : Am I able to build the following nested calls for the e...
function func1 ( callback ) { $ .ajax ( { //Ajax settings } ) .done ( function ( ) { console.log ( 'foo1 ' ) ; if ( callback ) callback ( ) ; } ) ; } function func2 ( callback ) { $ .ajax ( { //Ajax settings } ) .done ( function ( ) { console.log ( 'foo2 ' ) ; if ( callback ) callback ( ) ; } ) ; } function func3 ( cal...
Convert an array of functions into nested function calls
JS
How do I destructure width and height if they have been declared before ?
function test ( ) { let height let width const viewBox = ' 0 0 24 24 ' const sizeArr = viewBox.split ( ' ' ) // ESLint is telling me to destructure these and I do n't know how width = sizeArr [ 2 ] height = sizeArr [ 3 ] }
How to destructure this Array
JS
The code above takes an array of arbitrary length and checks each value . If the value of the bit of the array meets an arbitrary condition ( in this case if it is odd ) , then it is removed from the array.Array.prototype.splice ( ) is used to remove the value from the array , and then i is decremented to account for t...
var myArray = [ 1,2,3,4,5,6,7,8,9 ] ; function isOdd ( value ) { return value % 2 ; } for ( var i = 0 ; i < myArray.length ; i++ ) { if ( isOdd ( myArray [ i ] ) ) { myArray.splice ( i,1 ) ; i -- ; } }
When looping through values of a JS array , and I remove value , do I need to use while instead of for ?
JS
Ok I should know the answer to this but for some reason I have never really understood or had the need to really get to know JavaScript . My question is : Looking at the code samples below am I correct in my understanding or am I missing some information . Sample 1Need to instantiate the function ( or class ) in order ...
function MyClass1 ( ) { this.IsOld = function ( age ) { if ( age > 40 ) { return true ; } return false ; } ; } // sample usagevar m1 = new MyClass1 ( ) ; console.log ( m1.IsOld ( 34 ) ) ; var MyClass2 = ( function ( ) { function MyClass2 ( ) { } MyClass2.prototype.IsOld = function ( age ) { if ( age > 40 ) { return tru...
Fundamental JavaScript OO
JS
I know there are so many solutions out there but can not get right solution . I have written code for customized counter in tinyMCE version 3 which has maxlength attribute which is not working . I want to stop giving more text when counter reaches to 0 , I have used setcontent ( `` '' ) and substring ( 0 , maxcount ) t...
tinyMCE.init ( { mode : `` textareas '' , theme : `` advanced '' , editor_selector : `` mceEditor '' , paste_auto_cleanup_on_paste : 'true ' , theme_advanced_disable : 'justifyleft , justifyright , justifyfull , justifycenter , indent , image , anchor , sub , sup , unlink , outdent , help , removeformat , link , fontse...
Counter for TinyMCE is not working as expected
JS
Is there any difference between these two : and
var test1 = function ( ) { this.method1 = function ( ) { } } var test2 = function ( ) { } ; test2.method1 = function ( ) { } ;
What the difference between those two ?
JS
This question is about using Google Closure Compiler 's type annotations properly.We have a convention that every javascript file is wrapped in a function . Example file : Square.js : If we define a type ( such as a constructor ) inside this function , closure compiler is not aware of it in other files . For example , ...
( function ( ) { 'use strict ' ; /** * @ constructor */ function Square ( ) { } ; Square.prototype.draw = function ( ) { } ; } ( ) ) ; ( function ( ) { 'use strict ' ; /** @ param { Square } square */ function drawSquare ( square ) { square.draw ( ) ; } } ( ) ) ; foo.js:4 : WARNING - Bad type annotation . Unknown type ...
How to define global types when code is wrapped in functions
JS
There is a button labeled NEWFORM to create a new form when clicked . Each form has a submit button . When the submit button of each form is clicked , the values of that form will be sent via AJAX . My code works well the first time , but when a new form is created and submitted , all of the values of all forms will se...
$ ( document ) .ready ( function ( ) { $ ( `` .newform '' ) .click ( function ( ) { $ ( `` .MyForm '' ) .eq ( 0 ) .clone ( ) .show ( ) .insertAfter ( `` .MyForm : last '' ) ; } ) ; $ ( document ) .on ( 'click ' , '.MyForm button [ type=submit ] ' , function ( e ) { e.preventDefault ( ) // To make sure the form is not s...
How to Submit appended form separately
JS
I would like to merge 2 arrays : I would like to get the output like : or I have tried concat , but this is not keeping me the ID for each element.I am new in development overall , and I did n't find so far any results that would give me the proper output.Any hint how can I do this ?
arr1 = [ [ `` apple '' ] , [ `` banana '' , `` cherry '' ] ] arr2 = [ `` id1 '' , `` id2 '' ] result = [ [ `` apple id1 '' ] , [ `` banana id2 '' , `` cherry id2 '' ] ] result = [ [ `` apple from id1 '' ] , [ `` banana from id2 '' , `` cherry from id2 '' ] ]
How to concat 2 arrays , based on index
JS
I noticed today that jQuery 's : visible selector shows an unexpected behaviour when combined with an attribute selector . Its behaviour differs depending ona ) whether it is used inline or within the filter methodb ) the type of attribute selector it 's combined withExamples : Given the following markup The following ...
< input required name= '' name '' type= '' text '' / > $ ( ' [ required= '' required '' ] ' ) .filter ( ' : visible ' ) .length == 0 ; //true $ ( ' [ required= '' required '' ] : visible ' ) .length == 0 ; //false - why does jquery find the input ? < input data-boolean name= '' name '' type= '' text '' / > $ ( ' [ data...
Why does jQuery 's : visible selector work differently when filtered ?
JS
On C # , I 'm printing the JSONified string that I 'm sending to the console , and it reads asThen I do this to convert it to a byte array and send itAnd on the node.js side , I get this when console.logging res.body : That does n't look like valid JSON . What happened ? How can I send and receive the proper data ?
{ `` message '' : `` done '' , `` numSlides '' : 1 , `` slides '' : [ { `` num '' : 1 , `` key '' : `` 530d8aa855df0c2d269a5a5853a47a469c52c9d83a2d71d9/1slide/Slide1_v8.PNG '' } ] , `` bucket '' : `` xx.xxxxxxxxxx '' , `` error '' : null , `` wedge '' : false , `` tenant '' : null , `` name '' : null } WebRequest reque...
Converting an object into Json in C # and sending it over POST results in a corrupt object ?
JS
I want to know why i can use this.props directly but i ca n't use this.props from string into function.the error is : undefined is not an object ( evaluating 'this.props.navigation ' ) here a sample code i 've tried : but if i put stringToFn value into onPress directly or if i change this.state.stringToFn to this.state...
state= { stringToFn= '' this.props.navigation.navigate ( \'otherscreen\ ' ) '' , stringToFn2= '' alert ( \'otherscreen\ ' ) '' } renderThis ( ) { let nyobaFunc = new Function ( `` return `` + `` ( ) = > { `` +this.state.stringToFn+ '' } '' ) ( ) ; return ( < TouchableOpacity onPress= { nyobaFunc } style= { styles.flatL...
Can not access this.props from string to function
JS
This is my JSFiddleAs you can see from the fiddle that there is a list that is being scrolled with the help of arrows.. So what I want is to animate that transition when the list visible and hidden.I do n't know about the animation . I have seen many examples and tried to adjust them with my example but it 's not worki...
$ ( document ) .ready ( function ( ) { var code= '' ; for ( var i=1 ; i < =20 ; i++ ) { code+= '' < li > list Item `` +i+ '' < /li > '' ; } $ ( ' # list-items ' ) .html ( code ) ; } ) ; var list_items = [ ] ; var index = 0 ; var list_length = 0 ; function getAllListItems ( ) { var temp = document.getElementsByTagName (...
How to animate the list ?
JS
So the question is that two same objects are not equal in JavaScript , let 's say : or even : What 's the reason of this strange behavior ?
Object ( ) == Object ( ) [ { a : 1 } , { a : 2 } ] .indexOf ( { a : 1 } ) ; //returns -1 not found
Why Object ( ) ! = Object ( ) in JavaScript ?
JS
I am working on a existing project , and see this type of function export inside any file . So what does this syntax mean ?
export default ( variables /* : * */ = variable ) = > { ... }
What is meant by /* : * */ inside function argument ?
JS
What I am trying to do is redirect countries , based on country code with the script below . The code below does not work . Doing some research I found I have to use an or statement or at least that 's what I think I need , but my question is there an easier way then an or statement ? As you can see there are a lot cou...
< script language= '' JavaScript '' src= '' http : //j.maxmind.com/app/geoip.js '' > < /script > < script language= '' JavaScript '' > var country= geoip_country_code ( ) ; if ( country = `` UK '' , '' CA '' , '' DE '' , '' DK '' , '' FR '' , '' AU '' , '' SE '' , '' CH '' , '' NL '' , '' IT '' , '' BE '' , '' AT '' , ...
Alternative to OR statement
JS
Hi i have a problem when some dragged items have been dropped , I get this effect ( see pic ) . displayI think it might be something to do with ( negative ) -marginsbut I do n't know how to solve it . This only has to work on IE.My CSSHere is a jsfiddle incorrect display
window.onload = function ( ) { var target1 = document.getElementById ( `` fruit '' ) ; var target2 = document.getElementById ( `` veg '' ) ; var target3 = document.getElementById ( `` games '' ) ; var target4 = document.getElementById ( `` numbers '' ) ; var list = document.querySelectorAll ( `` # dragsource li '' ) ; ...
Incorrect display ( negative margins maybe ) ?
JS
Is there possible for the angular repeat to achieve that ? Basically Im wondering there is a way to loop the 2 together ? Really appreciate any help ! Controller : HTML : And I wish the column Bal and Order will repeat side by side under each date column .
$ scope.date= [ { ID:1 , Date : '2016-11-12 ' } , { ID:2 , Date : '2016-11-15 ' } , { ID:3 , Date : '2016-12-06 ' } ] < table border= '' 1 '' align= '' center '' > < tr > < th rowspan= '' 2 '' > ITEMCODE < /th > < th rowspan= '' 2 '' > DEBTORCODE < /th > < th colspan= '' 2 '' ng-repeat= '' d in date '' > { { d.Date } }...
How to make two column to repeat for one item in the list ?
JS
I 'd like to pull out the last class from css rules using Regex in javascript.The regex rule I 'm going for is to start searching from the end of the rule e.g . on '.myClass .myOtherClass ' and to bring back the first word after the last full stop - so the result there would be '.myOtherClass'Example css rules I need t...
.myClass { color : red ; } .myClass .myOtherClass { color : green ; } # something .somethingElse { color : blue ; } .something # myIdhere { color : purple ; } # myId { color : black } .myClass1 , .myClass2 { colour : green } .myClass span { colour : purple } .myPseudo : after { } .myClass.myOtherClass.somethingElse.som...
Regex to get the last css class
JS
What 's going on here : Obviously , one is being interpreted as UTC time , while the other two are being interpreted as local time . What causes the difference in parsing ?
> new Date ( 'Apr 15 2013 ' ) ; Mon Apr 15 2013 00:00:00 GMT+0100 ( GMT Daylight Time ) > new Date ( '04/15/2013 ' ) ; Mon Apr 15 2013 00:00:00 GMT+0100 ( GMT Daylight Time ) > new Date ( '2013-04-15 ' ) ; Mon Apr 15 2013 01:00:00 GMT+0100 ( GMT Daylight Time )
Why does javascript interpret these identical dates differently
JS
I have a jQuery code where I am trying to append to an existing div a label tag which contains a URL . Below is the code : When the page is actually displayed it shows the URL as : http : //financials.morningstar.com/ratios/r.html ? t=tup®ion=usa & culture=en-US
var strURL = 'http : //financials.morningstar.com/ratios/r.htmlt=tup & region=usa & culture=en-US ' ; var str = ' < li > ' ; str += ' < label style= '' font-family : Arial ; '' > ' + strURL + ' < /label > ' ; str += ' < /li > ' ; $ ( ' # existingDiv ' ) .append ( str ) ;
& reg becomes ® in jQuery
JS
How can you make the browser remember what the user typed in the form , which has not yet been submitted and make the page refreshing not affect the data entered ? I have a form in which the user enters a number . Initially the form has 0 by default . I am storing the data in localStorage , so the browser can remember ...
$ ( `` .formClassName '' ) .val ( localStorage.getItem ( key ) ) ; < form > < ! -- There are multiple forms , and the only difference among them is the `` name '' attribute -- > Enter a number < input type= '' text '' value= '' 0 '' class '' dataEntered '' name= '' **** '' > < ! -- The button below saves the data enter...
How to remember form data that has not been submitted ?
JS
I have written a terribly slow function for generating codes that go from AA000 to ZZ999 ( in sequence not random ) . And I have concluded that there has to be a better way to do this . Any suggestions on how to make this faster ?
function generateAlphaNumeric ( ) { theAlphabet = [ ' 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 ' ] ; resultArrray = [ ] ; resultArrray2 = [ ] ; teller = 0 ; for ( ...
Generating alphanumerical sequence javascript
JS
I 'm currently learning Rails , and I 'm wanting to use angular in my project . Here 's a simple application from scratch . 1 ) . Create a new rails app:2 ) . Add angular gem to Gemfile3 ) . Install the bundle4 ) . Add angular to javascript manifest in app/assets/javascripts/application.js5 ) . Generate welcome index6 ...
rails new hello_rails gem 'angularjs-rails ' bundle install //=require angular rails generate controller welcome index < div style = `` background-color : grey '' > this is index.html.erb < br > < div ng-app= '' '' > < p > Name : < input type= '' text '' ng-model= '' name '' > < /p > < h1 > Hello { { name } } < /h1 > <...
Rails javascript assets behaving oddly depending on routing
JS
I am trying to use JavaScript to set an elements width relative to their screen resolution width . I 'll explain a bit why ... I have this image : http : //i.stack.imgur.com/HeXvu.pngI want this to be my header , by I do n't want it to be a fully static image , I want the header to scale with the screen resolution , so...
< html > < body > < div class= '' globalContainer '' > < div id= '' headerMain '' > < div class= '' headerLeft '' > < /div > < div class= '' headerRight '' > < /div > < /div > < /div > < /body > < /html > # headerMain { height : 79px ; background-image : url ( ../img/global/middleHeader.png ) ; background-repeat : repe...
JavaScript , no idea what I am doing
JS
I study delimited continuations and am currently playing with discarding them to obtain an effect similar to raising exceptions.Here is what causes me trouble : It seems as if I can unwind the stack only by a single frame . Is this by design of shift/reset or caused by a flaw in my implementation ? [ EDIT ] I got it wo...
const structure = type = > cons = > { const f = ( f , args ) = > ( { [ `` run '' + type ] : f , [ Symbol.toStringTag ] : type , [ Symbol ( `` args '' ) ] : args } ) ; return cons ( f ) ; } ; const Cont = structure ( `` Cont '' ) ( Cont = > f = > Cont ( f ) ) ; const runCont = tf = > k = > tf.runCont ( k ) ; const reset...
How to discard a delimited continuation from within multiple nested functions ?
JS
I have a set of number input fields , labeled small & medium.. , and a set of div 's with the label small and medium . When you add a number to the small number input field a text input insertsAfter the div labeled small . When you subtract a number from the small number input field , the text input field that was rece...
< div id= '' product-1 '' > < div class= '' size-field '' > < div id= '' size-label '' > s < /div > < div class= '' number-input '' > < input id= '' Small '' class= '' product-quantity '' type= '' number '' name= '' Small '' min= '' 0 '' max= '' 9999 '' data-product-id= '' 1 '' > < /input > < /div > < /div > < div id= ...
associate number in number field with the number of newly created js div 's
JS
When I post the following code to console I got true : But when I do some calculation with it I got false : Why is it so ?
var a = 0 ; var b = -a ; console.log ( a === b ) ; // true console.log ( 1/a === 1/b ) ; // false
Why 0 === -0 is true , but 1/0 === 1/-0 is false ?
JS
I am having trouble transform a string using a certain mapping . The string I want to transform is the following : InputWhich can be better seen as the following ( very close to HTML ) : I am aiming to transform this into the following : Expected ResultHeres where I have gotten : It seems the recursion is not quite kic...
$ B $ O $ TT $ O $ $ KK $ $ Z $ HH $ $ U $ PP $ $ QQ $ U $ Z $ B $ $ B $ O $ TT $ O $ $ K K $ $ Z $ HH $ $ U $ PP $ $ QQ $ U $ Z $ B $ { `` v '' : `` B '' , `` chld '' : [ { `` v '' : `` O '' , `` chld '' : [ { `` v '' : `` T '' } ] } , { `` v '' : `` K '' } , { `` v '' : `` Z '' , `` chld '' : [ { `` v '' : `` H '' } ...
Transform string to object in Javascript
JS
I am new to JS and was trying to learn how to properly work with indexOf in JS , that is , if you look at the code below : I am trying to remove duplicates but wanted to ask two questions . Firstly , in here return sandwiches.indexOf ( sandwich ) === index ; why we need to use `` == index ; '' . Secondly , since indexO...
var sandwiches = [ 'turkey ' , 'ham ' , 'turkey ' , 'tuna ' , 'pb & j ' , 'ham ' , 'turkey ' , 'tuna ' ] ; var deduped = sandwiches.filter ( function ( sandwich , index ) { return sandwiches.indexOf ( sandwich ) === index ; } ) ; // Logs [ `` turkey '' , `` ham '' , `` tuna '' , `` pb & j '' ] console.log ( deduped ) ;
Confusion with how indexOf works in JS
JS
I have a JavaScript object : The output is as expected : My questions are : Is there any difference at all between these different methods of declaration ? Is it down to personal preference ? Or do the inner workings change ? Are there any considerations to take when using the different styles ?
var methods = { classStyle ( ) { console.log ( 'Class style function ' ) ; } , traditionalStyle : function ( ) { console.log ( 'Traditional style function ' ) ; } , arrowStyle : ( ) = > { console.log ( 'Arrow style function ' ) ; } } ; methods.classStyle ( ) ; methods.traditionalStyle ( ) ; methods.arrowStyle ( ) ; ( i...
What is the difference ( if any ) between the different function declarations within JavaScript objects ?
JS
I have a HTML String , called tinymceToHTML in my example and I had the problem that when I download this html String the images sources or hrefs were set wrongly . My image sources looked like `` /file/ : id '' in the original String , if I convert it into a DOM object and output the source it looks like `` http : //l...
var div = document.createElement ( 'div ' ) ; div.innerHTML = tinymceToHTML ; var images = div.getElementsByTagName ( 'img ' ) ; for ( var i = 0 ; i < images.length ; i++ ) { images [ i ] .src = images [ i ] .src ; } var a = div.getElementsByTagName ( ' a ' ) ; for ( var i = 0 ; i < a.length ; i++ ) { a [ i ] .href = a...
Why does assigning a variable to itself in a Dom Object make a difference
JS
I 'm very limited in my JS and even mathematics knowledge for that matter so I turn to you . I 'm using a site linked here to find annual population growth rates for individual Nigerian states . When you click on a state , say Abia , it will give you the annual growth rate . I 'm trying to figure out the exact formula ...
cp.data.computeAnnualChange=function ( a , b , c , d ) { if ( ! a|| ! b ) return null ; a=this.dateDiffInYears ( a , b ) ; return 0 < c & & 0 < a & & 0 < d ? Math.round ( 1E4* ( Math.exp ( Math.log ( d/c ) /a ) -1 ) ) /100 : null } ; cp.data.INT_MODE= '' i '' ;
Trying to understand how this webpage uses javascript to produce a growth rate
JS
My html code looks like this ... I am trying to get all the parent divs of li with class `` fruit '' that are within div with id=tropical ... I have done this much so far ... but it selects parents of < li > within div with id=sub_tropical
< div class= '' container '' > < div id= '' tropical '' > < div class= '' info '' > < div class= '' desc '' > < p > Lorem ipsum ... ... . < /p > < /div > < div class= '' list_of_fruits '' > < ul class= '' list '' > < li class= '' fruit '' > Avocado < /li > < li class= '' fruit '' > Banana < /li > < li class= '' fruit '...
Find parents of an element within a certain div
JS
I found this piece of code inside moment.js . Why would we have this kind of check ?
if ( locale === true || locale === false ) { strict = locale ; locale = undefined ; }
Javascript logical operation ( a === true || a === false )
JS
I 'm working on adding flow to a React.js app . I 've used flow-typed to add several packages , which seems to be working.This issue is that I 'm using the Material-UI beta . They do n't have a repo in flow-typed , but they do provide Component.js.flow files.However , I 'm getting this error : My .flowconfig : I 've tr...
Error : src/NotFound/NotFound.js:6 6 : import Button from 'material-ui/Button ' ^^^^^^^^^^^^^^^^^^^^ material-ui/Button . Required module not foundError : src/NotFound/NotFound.js:8 8 : import { withStyles } from 'material-ui/styles ' ^^^^^^^^^^^^^^^^^^^^ material-ui/styles . Required module not found [ ignore ] < PROJ...
How to consume third party .flow files ?
JS
I have the following code of a simple recursive function in javascript : which produce the following output : After banging my head on this very trivial code , i still do n't get why the stack exit value is decrementing ?
function print ( text ) { if ( ! text ) { throw 'No text in input ! ' ; } console.log ( 'print : '+text ) ; } function stack ( msg , stackSize ) { stackSize++ ; print ( 'Stack Entry '+stackSize ) ; if ( stackSize < 4 ) { stack ( msg , stackSize ) ; } else { print ( msg ) ; } print ( 'Stack exit '+stackSize ) ; } stack ...
Trouble with recursive javascript code ?
JS
I currently have a function that runs around 200 times.The function look like this : My first concern is that this array is slowing down everything because I think it is rewriting each time the array bxes ( or something like that ) This bxes array is never modified and I would n't mind to make it a global.Do I need to ...
function GetB ( av , bol ) { var bxes= [ [ `` 11 '' , '' 12 '' , '' 13 '' , '' 21 '' , '' 22 '' , '' 23 '' , '' 31 '' , '' 32 '' , '' 33 '' ] , [ `` 14 '' , '' 15 '' , '' 16 '' , '' 24 '' , '' 25 '' , '' 26 '' , '' 34 '' , '' 35 '' , '' 36 '' ] , [ `` 17 '' , '' 18 '' , '' 19 '' , '' 27 '' , '' 28 '' , '' 29 '' , '' 37...
Should heavy variables go outside functions ?
JS
I need your advice with my code . First , I show code : FiddleHow it works : Load page = show 10 < tr > s . When the user click button ( bottom ) , it shows 10 more rows but never show last . Do you know why and what have I to do with that problem ? When the 9 is changing to 4 , all works . Why ?
$ ( 'tr : gt ( 9 ) ' ) .hide ( ) ; $ ( 'button.btn-primary ' ) .on ( 'click ' , function ( ) { var visible = $ ( 'tr : visible ' ) .length ; $ ( 'tr : gt ( '+visible+ ' ) ' ) .slice ( 0,5 ) .show ( ) ; } ) < table class= '' table table-striped table-bordered '' > < thead > < tr > < th > Producent < /th > < th > Produkt...
Table rows show with button
JS
I have an array as follows : I just want to know how to get the unique objects inside it . I tried using lodash with this command : But it only returns : I want something like this one : Is there a way in lodash or vanilla JS to have this done ?
const arr = [ { company : ' a ' , date : ' 1 ' } , { company : ' b ' , date : ' 1 ' } , { company : ' c ' , date : ' 1 ' } , { company : ' a ' , date : ' 2 ' } , { company : ' a ' , date : ' 1 ' } , { company : ' b ' , date : ' 2 ' } , ] uniqBy ( arr , 'date ' ) ; [ { company : `` a '' , date : `` 1 '' } , { company : ...
Finding unique objects in array
JS
I try to write the function that returns all results of asynchronous functions and execute a callback that push into an array and log the result of every async function . As a waiter that brings all dishes when they are all done.I do n't understand how to get the child arguments that should be returned as a result . Th...
var dishOne = function ( child ) { setTimeout ( function ( ) { child ( 'soup ' ) ; } , 1000 ) ; } ; var dishTwo = function ( child ) { setTimeout ( function ( ) { child ( 'dessert ' ) ; } , 1500 ) ; } ; waiter ( [ dishOne , dishTwo ] , function ( results ) { console.log ( results ) ; // console output = [ 'soup ' , 'de...
JS : Get inner function arguments in asynchronous functions and execute callback
JS
QUESTION DOES NOT ALREADY HAVE AN ANSWER ( if you can provide code that works instead of googling my question and linking to whatever answer comes up for the sweet sweet internet points then I will accept it as an answer . But since I have already been to all of those questions do n't pretend like they work unless you ...
$ ( window ) .on ( `` mouseout '' , function ( ) { alert ( `` OUT '' ) ; } ) ;
How do you capture mouseout on window ?
JS
I want to make sure an error gets thrown when an attribute of an object gets changed outside the class . Here 's how I tried to do it : The error gets thrown just like I wanted , but the index value is undefined . I still want to be able to change the attribute inside of the class , but I want to prevent the attribute ...
class Example { constructor ( index ) { this.index = index ; Object.defineProperty ( this , 'index ' , { set ( ) { throw new AssertionError ( `` ca n't set attribute '' ) ; } } ) ; } } class AssertionError extends Error { constructor ( message ) { super ( ) ; this.name = `` AssertionError '' ; this.message = message ; ...
How to throw an error when an attribute is changed ?
JS
I am building an application which allows users to upload 3D models in the obj/mtl format . The admin displays a preview of what the loaded object will look like in our viewer . I would like to provide controls for the user to set the initial y-position of the loaded object , and the initial z position of the camera . ...
var obj3d ; loader.load ( model_obj , model_mtl , function ( object ) { object.position.y = y_init ; scene.add ( object ) ; render ( ) ; obj3d = object ; $ ( ' # initial_y ' ) .change ( function ( ) { obj3d.position.y = $ ( this ) .val ( ) ; } ) ; } , onProgress , onError ) ; Can not access property 'position ' of unde...
Access Object3D loaded using OBJMTLLoader
JS
I have been working with Angular JS for long time now , but just now faced a strange issue where ng-if is simply gets ignored with ng-repeat.This is the sample and simple code which does n't work as expectedHere is my plunkr : https : //plnkr.co/edit/xy4Qyd4tXm6kWROiaFVR ? p=preview
< ul ng-repeat= '' detail in details '' > < span ng-if= '' 2 == 3 '' > < ! -- This should block the next tags to execute -- > < li > { { detail.name } } < ul ng-repeat= '' detailed in details.name '' > < li > { { detailed.prof } } < /li > < /ul > < /li > < /span > < span ng-if= '' 2 === 2 '' > < ! -- Instead this shoul...
ng-repeat ignores immediate ng-if
JS
What mechanism permits a JavaScript function to refer to arguments from its caller by the name of the calling function and why is it still in the language ? I was looking up tail call optimization ( or rather the lack thereof ) in V8 and came across this post ( https : //code.google.com/p/v8/issues/detail ? id=457 ) Er...
function foo ( x ) { return bar ( x + 1 ) ; } function bar ( x ) { return foo.arguments [ 0 ] ; } foo ( 1 ) function foo ( x ) { return bar ( x+1 ) ; } function bar ( x ) { return foo.arguments [ 0 ] ; } console.log ( foo ( 1 ) ) ; // prints ' 1'console.log ( foo.arguments ) ; // prints 'null ' function variadic ( ) { ...
Why is it possible in JavaScript to refer to arguments in a caller ?
JS
I 'm not sure what is happening in this line of javascript : What I 've figured out : It seems that the second part is a reference into an array of letters or some sort , but I do n't understand how that is coming from Also :
alert ( ( `` + [ ] [ [ ] ] ) [ ! + [ ] + ! + [ ] ] ) ; // shows `` d '' var a = ! + [ ] ; // == truevar b = ! + [ ] + ! + [ ] ; // == 2 ( `` + [ ] [ [ ] ] ) alert ( ( `` + [ ] [ ] ) [ 2 ] ) ; // nothing happens ; console says `` unexpected token ] '' alert ( ( `` + [ [ ] ] [ ] ) [ 2 ] ) ; // nothing happens ; console s...
How is an array reference into an empty string + true a valid character in JavaScript ?
JS
When I have a code like this : Does the load send the request to load.php , if the # intro-posts-container element does n't exist ?
$ ( ' # intro-posts-container ' ) .load ( '/ajax/load.php ' , function ( ) { bindVoting ( ) ; } ) ;
Does jQuery load ( ) send any data even when the requested element is not found ?
JS
I ca n't find any right way to renew timer in toastrjs after hovering.I determinate a extendedTimeOut to 0 , to not close the toastr when I hover over it.The timeOut of toastr is 10000 ms , but when I 'm finished hovering , toastr is immediately getting hide.What 's the right way to show a toastr 10000 ms after I 'm fi...
const inboxToastr = toastr ; inboxToastr.info ( data.bubbleData , title , { `` tapToDismiss '' : false , `` closeButton '' : true , `` newestOnTop '' : false , `` progressBar '' : false , `` positionClass '' : `` toast-bottom-left '' , //position `` preventDuplicates '' : false , `` onclick '' : null , `` showDuration ...
toastrjs - renew timer after hovering
JS
Note : I 'm looking for vanilla JS preferably , since jQuery is n't something I can use in this projectI have a somewhat complex grid structure : I want to fire an animation when a user clicks one of those button elements using Anime.js , basically what amounts to a window blind or something similar to a window blind g...
body { margin : 0 ; height : 100vh ; text-align : center ; } .grid-container { height : 100 % ; display : grid ; grid-template-columns : 1fr 1fr ; grid-template-rows : 1fr 1fr ; grid-template-areas : `` tl tr '' `` bl br '' ; } .tl { background : # fdfdfd ; color : # 2f2f2f ; display : grid ; grid-template-columns : 1f...
CSS Grid fill animation on top of existing grid elements and take up full viewport
JS
I 've grown used to code my jquery animation by doing the following.Set the initial state of the element ( things like width , height , top , left , opacity , etc ... ) using either css or javascript . This initial state is the state at the end of the animation.Use .animate with 0 duration to move the element to the st...
/* css file */.animatedObject { width:60 % ; } // javascript file $ ( '.animatedObject ' ) .animate ( { width : '-=20 % ' } , 0 ) .animate ( { width : '+=20 % ' } , 1000 ) ;
Is it okay to use .animate with 0 duration all the time ? Is there a better alternative ?
JS
I wanted to experiment a bit with the Proxy object , and got some unexpected results , as follows : Test scriptSo in tracking how the prototype object is being modified , I added this wrapper : What I expectedand nothing else.And of course , each time I added or removed something from the prototype , i.e Person.prototy...
function Person ( first , last , age ) { this.first = first ; this.last = last ; this.age = age ; } Person.prototype.greeting = function ( ) { return ` Hello my name is $ { this.first } and I am $ { this.age } years old ` ; } ; let validator = { set : function ( target , key , value ) { console.log ( ` The property $ {...
Why does the Proxy object reflect changes beyond the target object ?
JS
What is the difference between creating an object using an inline object constructor and creating an object by immediately invoking a contructor ? I have always done the latter as it free 's me from having to call something like init ( ) myself and feels like the right thing to do , but I keep seeing the object notatio...
window.fooModule = { init : function ( ) { this.bar = `` cee '' ; doStuff ( ) ; } , doStuff : function ( ) { ... } } window.fooModule.init ( ) ; window.fooModule = new function ( ) { this.bar = `` Cee '' ; this.doStuff = function ( ) { ... } this.doStuff ( ) ; }
Difference between different object notations
JS
This is what i have so far : } What i 'm trying to do is to add a css style to a sprecific li by calling it by it 's nth-child position , so what i tryied was this : Of course that did n't work . I 'm a beginner so my code may be very inefficient , but i 'm not worried about that right now , what i want is to add a dif...
function listarRestaurantes ( ) { for ( i=0 ; i < restaurantes.length ; i++ ) { if ( restaurantes [ i ] [ 'nombre ' ] .length > = 0 & & restaurantes [ i ] [ 'nombre ' ] .length < = 11 ) { $ ( `` p.nombre_res '' ) .css ( 'line-height ' , '140px ' ) ; $ ( `` # col_derecha ul '' ) .append ( `` < li class='restaurantes ' >...
Use iterator variable on element name ?
JS
If i have code : is B function parsed and created each time i call A ( so it can decrease performance of A ) ?
function A ( ) { function B ( ) { } B ( ) ; } A ( ) ; A ( ) ;
Function definition inside function
JS
EDIT : After some re-working to use another method ( createElement ) I 've gotten my code to the point where it can properly call on elements , however it only uses the parameters of the last banner made at the end of the function . Here 's the snippet of what I have to date.First time posting here , my apologies in ad...
function load ( ) { var staffB = [ `` Admin '' , `` GM '' , `` Dev '' , `` FM '' , `` Lore '' , `` App '' , `` Magic '' , `` Event '' ] ; var table = document.createElement ( `` table '' ) ; for ( var staffI = 0 ; staffI < staffB.length ; staffI = staffI + 2 ) { var row = document.createElement ( `` tr '' ) ; var td = ...
Calling a function via created HTML code
JS
I have to convert user entered unordered lists in a content management system into a bootstrap menu ( navbar ) using jquery.80 % there apart from one challenge that I ca n't figure out a nice solution for - ie one that uses selectors rather than string manipulation or regex . After all , we all know that we never parse...
< ul > < li > Blah1 < ul > < li > < a href='http : //xxxx ' > Blah1a < /a > < /li > < li > < a href='http : //yyyy ' > Blah1b < /a > < /li > < li > Blah1c < /li > < li > < a href='http : //zzzz ' > Blah1d < /a > < /li > < /ul > < /li > < li > < a href='http : //aaaa ' > Blah2 < /a > < /li > < li > Blah3 < ul > < li > <...
Selecting list items that are not links
JS
The typescript code is as above , my question is that is n't the last three lines the same ? Why the first line can pass and the second line get a complaint , and the third line get a pass ? Also on the typescript playground : playground
type ExpectedType = Array < { name : number , gender ? : string } > function go1 ( p : ExpectedType ) { } function f ( ) { const a = [ { name : 1 , age : 2 } ] go1 ( a ) // does n't complain go1 ( [ { name : 1 , age : 2 } ] ) // complain 'Object literal may only specify known ... ' go1 ( [ 'no matter ' ] .map ( n = > (...
Why can I assign unknown properties to literal object in typescript ?
JS
I recently read a javascript code and I came across this line : What is this strange syntax : ( x , y ) ?
var myVar = ( 12,5 ) ; // myVar==5 now
What is the name of this syntax `` ( x , y ) '' ?
JS
I add an event on click of my button : In the turnOn method I add a listener on the document , to run the turnOff method.Then during testing , I click the button and the turnOn method runs , but that initial click also runs the document click listener.How can I run the turnOn method , add the document listener , but no...
this. $ refs.btn.addEventListener ( 'click ' , this.turnOn ) ; turnOn ( ) { document.addEventListener ( 'click ' , this.turnOff ) ; }
Event listener added on click but runs straight away ?
JS
In node v14.3.0 , I discovered ( while doing some coding work with very large arrays ) that sub-classing an array can cause .slice ( ) to slow down by a factor 20x . While , I could imagine that there might be some compiler optimizations around a non-subclassed array , what I do not understand at all is how .slice ( ) ...
Running with Array ( 100,000,000 ) sliceTest : 436.766mscopyTest : 4.821sRunning with ArraySub ( 100,000,000 ) sliceTest : 11.298scopyTest : 4.845s // empty subclass for testing purposesclass ArraySub extends Array { } function test ( num , cls ) { let name = cls === Array ? `` Array '' : `` ArraySub '' ; console.log (...
Why is array.prototype.slice ( ) so slow on sub-classed arrays ?
JS
I was referring docs of JavaScript var hoisting , There in a section i found Initialization of several variables with a Example given below.Where I Suppose to get Exception as Uncaught Reference Error : y is not defined.but it is not happening due to leaked Scope and it is displaying 0,1.Can I Know why it is happening ...
var x = 0 ; function f ( ) { var x = y = 1 ; } f ( ) ; console.log ( x , y ) ; // outputs 0 , 1// x is the global one as expected// y leaked outside of the function , though !
Why Initialization of several variables leading into Scope Leakage ?
JS
I have a function which is triggered on a click event . Inside the function first line is to show an overlay , and after that there is a for loop . I expect the function to show the overlay first and then continue with the for loop.Instead overlay is being shown only after the for loop completes.Here is the jsFiddle Li...
$ ( document ) .on ( `` click '' , function ( ) { $ ( `` h1 '' ) .text ( `` Clicked '' ) ; for ( var i=0 ; i < 100000 ; i++ ) { console.log ( i ) ; } } )
jquery waits the for loop to complete before executing previous events
JS
I have a specific requirement where I have to update a dataTable by onchange event of a selectOneMenu but it seems that the dataTable is not getting updated . I 've tried to use triggerChange ( ) function , with no luck . Please find the below code that I have tried.xhtmljavascriptThe above function does not get called...
< p : selectOneMenu id= '' id '' style= '' width:250px '' value= '' # { priceCharterMBean.traffic.id } '' required= '' true '' requiredMessage= '' Traffic is required '' filter= '' true '' filterMatchMode= '' startsWith '' widgetVar= '' w_menu '' onchange= '' updateTable ( ) ; '' > < p : ajax event= '' change '' proces...
triggerChange ( ) function not working in JSF ?
JS
I found this example code : Which alerts `` Michael Jackson '' . I changed it to call personFullName from the constructor instead of assigning the function object : I would expect the `` fullName '' property to now be a string instead of a function . But now it alerts `` undefined undefined '' . Can anyone explain why ...
function personFullName ( ) { return this.first + ' ' + this.last ; } function Person ( first , last ) { this.first = first ; this.last = last ; this.fullName = personFullName ; } var dude = new Person ( `` Michael '' , `` Jackson '' ) ; alert ( dude.fullName ( ) ) ; function personFullName ( ) { return this.first + ' ...
How does `` this '' work in functions that are assigned in the constructor ?
JS
I have an array that I want to use as the keys to my map and set each value to true . Is there a way to do this besides using a forEach loop on my array to set each entry ? This is how I am doing it now : Is there a better way ?
const list = [ 0 , 1 , 2 , 3 ] ; const myMap = new Map ( ) ; list.forEach ( element = > myMap.set ( element , true ) ) ;
Is there a way to set all of the entries of a map to a value
JS
Take a look at the following code : When you inspect new Human ( ) , there 's no hairy member . I would expect there to be one . Is there another way I 'm suppose to inherit from Primate ? Something involving Object.create ( ) ( ECMAScript5 is fine to use in my scenario ) ?
function Primate ( ) { this.prototype = Object ; this.prototype.hairy = true ; } function Human ( ) { this.prototype = Primate ; } new Human ( ) ;
JavaScript inheritance : When where 's my derived members ?
JS
I 'm currently trying to rebuild a section of a website where I do n't have access to the DOM . Initially the section was built with tables and now I 'm trying to rebuild the structure in divs . I 've gotten as far as having one parent container with all contents of the table as children , like so : Chrome console wind...
$ ( `` # button '' ) .click ( function ( ) { $ ( ' # ProductDataList ' ) .replaceWith ( function ( ) { $ productListContainer = $ ( `` < div > '' , { html : $ ( this ) .html ( ) } ) ; $ .each ( this.attributes , function ( i , attribute ) { $ productListContainer.attr ( attribute.name , attribute.value ) ; } ) ; return...
How to wrap every third unique child element in new div
JS
ProblemI have a string of numerical values separated by commas , and I want to include them in an array , and also each pair of them to be an array nested inside of the main array to be my drawing vertices.How do I solve this problem ? Input : what I want them to be is : Output :
var vertices = `` 24,13,47,20,33,9,68,18,99,14,150,33,33,33,34,15,91,10 '' ; var V_array = [ [ 24,13 ] , [ 47,20 ] , [ 33,9 ] , [ 68,18 ] , [ 99,14 ] , [ 150,33 ] , [ 33,33 ] , [ 34,15 ] , [ 91,10 ] ] ;
Create an arrays inside of another ( main ) array out of separated values
JS
I am initializing a WKWebView with a script that injects cookies . The script has the form : But , after I load a url and inspect the cookies , the cookie has a domain= '' .stage.site.com '' Does someone know why the dot is being added ? This is causing problems downstream as I now have duplicate cookies .
document.cookie = 'mycookie=2bxxx962-b525-4afb-88de-ae4f12ecaxxxx ; domain=stage.site.com ; path=/ ; expires=Fri , 10 Apr 2020 21:32:50 GMT ' ;
Unexpected cookie domain after injecting cooking script to WKWebView
JS
I have found two ways of using Javascript 's native bind as I migrate away from jQuery.proxy ( ) : andAs far as I can tell , they both do the same thing , but I 'm worried that the latter might cause issues in the on ( ) ( or any function in its place ) . The former syntax is what I 'm used to from $ .proxy ( ) , and t...
this.thing.on ( event , someHandler.bind ( this ) ) this.thing.on ( event , someHandler ) .bind ( this )
What is the correct Javascript bind syntax ?
JS
I am reading You Do n't Know JS : ES6 & Beyond and I encountered this snippet in Symbol.species section.It seems like the function Symbol.species { return Something } should always return a constructor function . But in the first presence of this function : static get [ Symbol.species ] ( ) { return this ; } I am confu...
class Cool { // defer ` @ @ species ` to derived constructor static get [ Symbol.species ] ( ) { return this ; } again ( ) { return new this.constructor [ Symbol.species ] ( ) ; } } class Fun extends Cool { } class Awesome extends Cool { // force ` @ @ species ` to be parent constructor static get [ Symbol.species ] ( ...
What does this in this snippet ?
JS
I 'm receiving a string from the backend . Let 's sayAt the frontend , I 'm using javascriptI want to know how can I bind name from the variable getting in the string.I know about the string interpolation in JS like belowEven on using string interpolation is not helping me andI 'm getting normal string from backend lik...
`` Save Earth , $ { name } '' ` Save Earth , $ { name } ` const name = `` John '' ; const response = `` Save Earth , $ { name } '' ; console.log ( ` $ { response } ` ) ; `` Save Earth , $ { name } '' `` Save Earth , John ''
how I convert string into interpolated string ?
JS
Having an HTML snippet like this : I can select the < mark > elements using $ ( `` mark '' ) . I want to get a list of strings representing the marked word and 5 characters on the left side and 5 characters in the right side and prefix and suffix the strings with [ ... ] .For this example it would be : Currently I 'm s...
< p > Lorem ipsum < mark > dolor < /mark > sit amet . < mark > Lorem < /mark > ipsum again and < mark > dolor < /mark > < /p > [ `` [ ... ] psum dolor sit [ ... ] '' , `` [ ... ] met . Lorem ipsu [ ... ] '' , `` [ ... ] and dolor [ ... ] '' , ] var $ highlightMarks = $ ( `` mark '' ) ; var results = [ ] ; for ( var i =...
Getting text around a specific element reference
JS
The idea : I am trying to simulate a shop system . By clicking on items the users shows that he is interested in stuff like that and gets more like it the next time he visits the website . I want to achieve something similar only without things to buy , but with colors . You get random colors . If you 'like ' red color...
var r = getCookie ( `` r '' ) ; var g = getCookie ( `` g '' ) ; var b = getCookie ( `` b '' ) ; if ( r = `` '' ) { setCookie ( `` r '' ,1.0,365 ) ; setCookie ( `` g '' ,1.0,365 ) ; setCookie ( `` b '' ,1.0,365 ) ; } init ( ) ; function init ( ) { var colorboxes = document.getElementsByClassName ( `` mycolorbox '' ) ; [...
Random Colors with preference
JS
I have the following code in my HTML file : See fiddle : http : //jsfiddle.net/sebvaeja/Looking at the console , you can see that window.never function is actually called ( 'this function is never called ' is written to the console ) .When debugging this with Chrome dev tools , I see in the call stack that the caller w...
< script type= '' text/javascript '' > window.never = function ( ) { console.log ( 'this function is never called ' ) ; } ( function ( d , s , id ) { var js , srjs = d.getElementsByTagName ( s ) [ 0 ] ; if ( d.getElementById ( id ) ) { return ; } js = d.createElement ( s ) ; js.id = id ; js.src = `` this.script.does.no...
Why is the function called ? JavaScript / Window
JS
I came across this post on this site with a jFiddle showing a following menu for JQUery , well I saw this piece of syntax I ca n't figure out.JFiddle : http : //jsbin.com/oxajeq/3/edit ? html , css , js , console , outputLine of code I do NOT understandI know the first part selects the element with id of mini-logo , bu...
$ ( ' # mini-logo ' ) [ logoSH ] ( 300 ) ;
What does this line of JQuery code mean ?
JS
I have this range of numbers : I want to recieve a number between 0 to 150 and to display whether it is small , medium or big.30 and 45 are medium because they are between 25 and 80 and 5 is small because it is lower than 25.I want to create a function that does this matching for this object : ( assuming that 0 is the ...
0 -- -- -- - > 25 -- -- -- - > 80 -- -- -- > 150 small medium large var sizeMap = { small : 25 , medium : 80 , large : 150 } function returnSize ( number ) { for ( item in sizeMap ) ? ? ? ? ? ? ? return size }
How to create a function that determines value between 2 numbers
JS
So I 'm making a website for someone and I 'm quite new to jQuery ( which probably does n't help ) . The site needed a dropdown menu to display links to the galleries in a list rather than having them all in the navigation bar . The problem is , whenever I hover over the li element the dropdown slides down but when I h...
$ ( document ) .ready ( function ( ) { $ ( `` li # navi-dropdown '' ) .hover ( function ( ) { $ ( 'ul.nav-dropdown ' ) .slideDown ( 'medium ' ) ; } , function ( ) { $ ( 'ul.nav-dropdown ' ) .slideUp ( 'medium ' ) ; } ) ; } ) ;
Can not keep jQuery dropdown slide down
JS
Having the reference to a specific DOM element ( e.g . < mark > ) , how can we get the full word containing that element ? For example : I expect to get the following output : First < mark > : HelloSecond : WorldThird : HelloFourth : Pluto
H < mark > ell < /mark > o Wor < mark > l < /mark > d , and He < mark > llo < /mark > , < mark > Pluto < /mark > ! var $ marks = $ ( `` mark '' ) ; var tests = [ `` Hello '' , `` World '' , `` Hello '' , `` Pluto '' , ] ; function getFullWord ( $ elm ) { // TODO : How can I do this ? // This is obviously wrong . return...
Get full word containing a specific element
JS
I have month array which should be rotate left to right for its length time . Store all rotational array in object variable . Can you please suggest more efficient way to do it.I have tried this below method .
var Month = [ `` Jan '' , `` Feb '' , `` Mar '' , `` Apr '' , `` May '' , `` June '' , `` July '' , `` Aug '' , `` Sep '' , `` Oct '' , `` Nov '' , `` Dec '' ] ; Output looks like : monthRotate = { rotate1 : [ `` Feb '' , `` Mar '' , `` Apr '' , `` May '' , `` June '' , `` July '' , `` Aug '' , `` Sep '' , `` Oct '' , ...
Rotate array and store all combination in object variable