lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
How do I retrieve values from @ for loop into jquery..Each value inside for loop should have different id , and jquery should get each separate id ... .My for loop , My jquery which is n't helping , Thanks in advance ...
@ for ( int i = 0 ; i < searchList.Count ; i++ ) { < label for= '' input @ i '' > < input type= '' checkbox '' id= '' input @ i '' / > @ searchList [ i ] < /label > } $ ( `` # input @ i '' ) .on ( `` click '' , function ( ) { var currentChk = $ ( this ) ; var propCheck = currentChk.prop ( `` checked '' ) ; if ( propChe...
Retrieving values from for loop into jquery
JS
I have a doubt My Code : -How do I can call g ? I want to return 1 once and again I want to return g.I did a Research I found a solution How we can call g is : - Why this is ? ? What is f ( ) ( ) ; in JavaScript . why not we can achieve this using f.g or something.How can I return g from the function f ? ? Please clari...
function f ( ) { var g = function ( ) { return 1 ; } return g ; } ; f ( ) ( ) ;
javascript function with in function in variable
JS
I have an array of objects : Now I have another array of orders with the help of which I want to sort items array : Now what I am trying so far in my logic is that I am putting so many loops that it is totally creating mess.Can anyone suggest me with a short and optimized logic for this ?
var items = [ { `` id '' : '' sugar '' , `` type '' : 'eatables ' } , { `` id '' : '' petrol '' , `` type '' : 'utility ' } , { `` id '' : '' apple '' , `` type '' : 'fruits ' } , { `` id '' : '' mango '' , `` type '' : 'fruits ' } , { `` id '' : '' book '' , `` type '' : 'education ' } ] ; var orders = [ { `` id '' : ...
Sort array of objects by given incomplete array of orders in Javascript
JS
I have the following three variables assigned : When I then try to logged the following into the console : I got the following : When I thought I should get : Why am I wrong and how can I fix it ?
const a = { key : true } const b = { key : false } const c = { [ a ] : ' 1 ' , [ b ] : ' 2 ' } console.log ( c [ a ] , c [ b ] ) 2 2 1 2
Why are two different keys overriding each other in an object ?
JS
The problem is next . I created an input field which has validation and this is valid data:1-12 , 14 , 16 , 22 , 25-35 , 41 , 49 , 55-901230-1992 , 2001-2099 , 99311-2131,3,4,5,6,10allBasically , any combination of those numbers ( ranges , comma-separated ranges , comma-separated number , spaces after commas , no space...
$ ( `` input [ type='text ' ] '' ) .blur ( function ( ) { //when you lose focus on input doneTyping ( ) ; } ) ; function doneTyping ( ) { if ( ! $ ( ' # inputToCheck ' ) .val ( ) .match ( /^ ( ( [ 0-9 ] { 0,4 } , ? \s { 0 , } ) + ( [ 0-9 ] { 1,4 } \- [ 0-9 ] { 1,4 } ) { 0 , } , ? \s { 0 , } ) + $ |^ ( all ) $ |^ ( [ 0-...
Browser tab stucks when my RegEx is executed and do not match the input
JS
I am reviewing a JavaScript code from a colleague and he wrote an Object prototype function that I believe is not correct regarding the principles of Object-Oriented Programming.A couple of lines below , the game variable was declared as a global variable.So , is it correct to create a new Game object from one of its c...
Game.prototype.reset = function ( ) { if ( game.over ) { game.over = false ; game = new Game ( players ) ; } } var game = new Game ( players ) ;
Is it correct to invoke the constructor of a JavaScript Object in one of the prototype functions ?
JS
I was reading this article about how jQuery works , and that article minified jquery structure into symbolic code : Line # 32 is where the magic happens . so when I 'm writing jQuery ( .. ) it actually run new init ( ) which has access to all jQuery.fn functions.It 's pretty clear ( most of it ) but I have 2 questions ...
/*1*/ var jQuery = ( function ( ) /*2*/ { /*3*/ /*4*/ /*5*/ var jQuery = function ( selector , context ) /*6*/ { /*7*/ /*8*/ /*9*/ return new jQuery.fn.init ( selector , context , rootjQuery ) ; /*10*/ } , /*11*/ rootjQuery ; /*12*/ /*13*/ /*14*/ jQuery.fn = jQuery.prototype = { /*15*/ constructor : jQuery , /*16*/ ini...
jQuery structure - clarification ?
JS
I have an array of sentences of varying lengths . Let 's assume it looks like this : What I need is to build another array of sentences based on the first one , with each element as big as possible but under 100 characters . On the contrary , sentences longer than 100 characters should be split into smaller chunks . So...
sentences = [ `` Far far away , behind the word mountains , far from the countries Vokalia and Consonantia , there live the blind texts . '' `` I never thought that would happen ! `` , `` This one ? `` , `` No , no , that one . `` , `` Okay but please ensure your sentences are long enough to be split when longer than 1...
How to process an array of sentences to return another array with longest possible sentences below x characters ?
JS
Let 's say I have a performance-optimized component like this one : and I am using the component inside the parent like this : I am passing different objects for style , it can look like this : Now React.memo will not do the trick because I am passing an object and React will only compare the memoryaddress ( I think it...
const PerformanceComponent = ( { style } ) = > { return < View style= { style } > ... < /View > } export default React.memo ( PerformanceComponent ) { someArray.map ( ( style ) = > ( < PerformanceComponent style= { style } / > ) } const styles = { width : 200 , height : 200 }
Avoid rerendering child when passing object in props
JS
In Javascript it 's different to use a.b ( c ) or [ a.b ] [ 0 ] ( c ) the reason being the binding of this to the object a or not during the execution of the code of a.b.Following the same reasoning usingcould in theory be different from console.log ( Math.cos ( 1 ) ) but does n't seems so in practice.The question is :...
var z = Math.cos ; console.log ( z ( 1 ) ) ;
Is it guaranteed that ` Math.cos ( 0 ) === [ Math.cos ] [ 0 ] ( 0 ) ` ?
JS
I have a js class that has a BehaviorSubject and an Observable . I want to subsribe to the Observable in a different class , which does not work , properly . So My main questions : How can I make sure that the subscriber gets all the changes in ClassTwo ? Note that the Observable is defined and fires once , but is not ...
//class One : export default ClassOne { constructor ( ) { this._store = new BehaviorSubject ( { } ) ; this.store = this._store.asObservable ( ) ; this.store.subscribe ( data = > { console.log ( data ) } ) //logs the data , no Problem here // { } ; { test : { foo : `` bar '' , max : `` muster '' } } ; { test : { foo : `...
rxjs : Subscriber does not fire on all changes in different class
JS
I have javascript file called screener.jsfrom the index.html file I include the javascript file like this : Then later in the head section of index.html I instantiate the screenerPage object like this : Then down in the body section there is a select with onchange event that calls but the browser shows error : Uncaught...
function ScreenerPage ( ) { function onScreenListChange ( ) { do stuff } ; } < script type= '' text/javascript '' src= '' ./js/screener.js '' > < /script > < script type= '' text/javascript '' > $ ( document ) .ready ( function ( ) { screenerPage = new ScreenerPage ( ) ; } < /script > < select id= '' screenList '' onch...
how to call a javascript function within a function
JS
Consider a service : And a controller : Also consider a markup that binds both scope propertiesWhen those values get updated through the view via user input , my service will show only those changes made to the object , while the string property stays empty.Am I right in assuming that this is caused by the fact that th...
app.service ( 'myService ' , function ( ) { this.strProp = `` ; this.objProp = { content : `` } } ) app.controller ( 'myCtrl ' , function ( $ scope , myService ) { $ scope.str = myService.strProp ; $ scope.obj = myService.objProp ; } ) < input type= '' text '' ng-model= '' str '' > < input type= '' text '' ng-model= ''...
Binding to service property only via reference ?
JS
When creating jQuery objects I 've used the following syntax lately , as described here : Safari 5.0.5 gives a syntax error at the point where I use the above construction . Removing the second argument and adding classes with addClass removes the error , but seems rather unelegant . How do you create your objects ? I ...
var $ el = $ ( ' < div/ > ' , { class : 'class-1 class-2 ' } ) ;
What 's the preferred way to create a jQuery object with attributes ?
JS
I have the following code which is basically a container that has a width and is then filled up with squares so there is an equal number of squares accorss and down : My question is why does the .container lose 10px in height ( if you inspect element it is only 950px high ) , even though the squares inside are square ,...
var container = $ ( '.container ' ) , numberOfSquares = 25 , squareSize = container.width ( ) / numberOfSquares ; for ( var squares = 0 ; squares < numberOfSquares * numberOfSquares ; squares++ ) { $ ( ' < div class= '' gridSquare '' > < /div > ' ) .appendTo ( container ) ; } $ ( '.gridSquare ' ) .css ( { `` height '' ...
Why does the container lose 10px height ?
JS
I am building a chess game in javascript right now , and am a little unsure about the correct way to work with inheritance . On one part of the code I have a piece object with different piece types extending it , for example with a knight ( as it 's the shortest ) it looks like this ( without the comments ) : piecesAnd...
/************* piece ********************/function Piece ( square , color ) { this.square = square ; this.color = color ; } Piece.prototype.get_path = function ( to ) { return null ; } ; Piece.prototype.get_capture_path = function ( to ) { return this.get_path ( to ) ; } ; Piece.prototype.isAt= function ( square ) { re...
In javascript , should I add functions to object or object prototype
JS
I wanted to make an effect similar to `` click and hold '' of this page , but with some changes , with svg forms , the point is that I did two functions that do what I wanted to do very well , but at the moment I introduced another svg form , the Data of the effect is transferred to the other , affecting the execution ...
//Efect Driversclass EffectValues { constructor ( count , time , initOffset , label ) { this.count = count ; this.time = time ; this.initOffset = initOffset ; this.label = label ; } } //Controlerslet counter ; //it will be interval controllerlet globalCount = 0 ; //Call objects DOMconst loader = document.querySelector ...
how can I reuse the functions of my code javascript ?
JS
I am trying to insert additional characters in a specific string.By using onchange attribute in htmlinput , the code runs perfectly . But can this also run with onkeypress attribute ? If value of inputs is 1006 , the result should be 10'06 '' . Help . Thanks .
function sample ( x ) { if ( x.value.length > 2 & & x.value.length < 5 ) { var first = x.value.substring ( 0 , 2 ) + `` ' '' ; var second = x.value.substring ( 2 , x.value.length ) + `` '' '' ; x.value = first + `` '' + second ; } } < input id= '' txt '' type= '' text '' placeholder= '' onkeypress '' onkeypress= '' sam...
Characters inserting in wrong index of the string
JS
I have a couple of jQuery functions that pass PHP data to the JS function using the wordpress wp_localize_scripts function : Which would output an array with all the needed data for the JS function : However , it does n't seem to be working as I thought it would when it was n't being passed via the array and was all ha...
function mb_scripts_settings ( ) { // blanks $ mb_ajax_form_type = $ mb_get_page_slug = $ mb_redirect = $ mb_redirect_time = $ mb_form_disable = $ mb_array = `` ; // get the form type $ mb_ajax_form_type = ( is_front_page ( ) ? 'change ' : 'submit ' ) ; // get the page slug from ID $ mb_get_page_slug = get_post_field (...
PHP variables in jQuery function not correctly passing
JS
I 'm trying to create a function that returns true if at least one of the elements of a string array is found within another string.This function does the trick , but I 'm sure there might some array or string method that does the same without having to loop through the array . Any ideas ? Thanks .
function findInString ( str ) { var fruits = [ `` orange '' , `` banana '' , `` grape '' ] ; for ( var i = 0 ; i < fruits.length ; i++ ) { if ( str.indexOf ( fruits [ i ] ) > -1 ) { return true ; } } return false ; } var a = findInString ( `` I love orange juice . `` ) ; //= > returns truevar b = findInString ( `` I do...
Match one of the elements of an array in a string using javascript
JS
I know that this can be done for anonymous functionsI have a function that I wish to use in other places , but should also be executed immediately . Is it possible to do it with one statement instead of the following ? The return value is n't needed .
( function toBeExecutedImmediately ( ) { // Code } ( ) ) ; function toBeExecutedImmediately ( ) { // Code } ; toBeExecutedImmediately ( ) ;
Executing a named function after declaring it
JS
I have two instances of an object that extends EventEmitter and listens to an event called finish . If I set the event handler outside the constructor everything works as expected . Each instance hears the occurence of finish that it triggers . But if I set the event handler inside the constructor , only the instance c...
var util = require ( 'util ' ) ; var EventEmitter = require ( 'events ' ) .EventEmitter ; var fs = require ( 'fs ' ) ; var NEXT_ID = 0 ; var MyEmitter = function ( ) { EventEmitter.call ( this ) ; this.id = NEXT_ID ; NEXT_ID++ ; console.log ( 'CREATED EMITTER WITH ID : ' , this.id ) self = this ; this.on ( 'finish ' , ...
Event handler in constructor behaves differently than event handler out of constructor
JS
Trying to get clipboard content as a string variable ( for example page url is copied ) ; The code below returns undefined in console .
function get_clip ( ) { navigator.clipboard.readText ( ) .then ( text = > { return text ; } ) .catch ( err = > { console.error ( 'Failed to read clipboard contents : ' , err ) ; } ) ; } var str = get_clip ( ) ; console.log ( str ) ; < script src= '' https : //cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ''...
getting clipboard content as a string variable
JS
Reading through the knockout.js source code I come accross this lineI 've never seen this before and everything I know about javascript says there is no case when the two sides of the || would be different . Why might have the knockout team used this construct ?
disposeWhenOption = options [ `` disposeWhen '' ] || options.disposeWhen
Why do options [ `` foo '' ] || options.foo ?
JS
So I 'm trying to do some calculations inside a HTML table with Javascript/Jquery . There are 7 columns in 1 table and each column should do their calculations based on the values that are in the cells in those columns.I did manage to make this work for one , but once I try coding it so it works for every column I get ...
var aankoopprijs = $ ( `` .calc-aankoop '' ) .text ( ) ; var ob = $ ( `` .calc-ob '' ) .text ( ) ; var add = parseFloat ( aankoopprijs ) - parseFloat ( ob ) ; $ ( `` .calc-marktprijs '' ) .html ( add ) ; //Calculate the Groothandelprijsvar marktprijs = $ ( `` .calc-marktprijs '' ) .text ( ) ; var kruissubsidie = $ ( ``...
Calculating data in tables with Javascript/Jquery
JS
All over MDN , the documentation represents arguments like this value [ , replacer [ , space ] ] . What is the reason behind it ? What are the purpose of the square brackets ?
JSON.stringify ( value [ , replacer [ , space ] ] )
Why arguments in all JavaScript Documentation are written like this ?
JS
I have searched many topics but I did not find the exact solution for my problem.I need to create a dropdown which will be placed at whole website because you always can change your location to another city to see the offer . I would like to create a dropdown where customer selects his city for a local delivery . This ...
< script type= '' text/javascript '' > if ( localStorage & & localStorage.country ) { location = localStorage.country ; } function formChanged ( form ) { var val = form.options [ form.selectedIndex ] .value ; if ( val ! == 'non-value ' ) { if ( localStorage ) { localStorage.country = val ; } location = val ; } } < /scr...
Dropdown redirect with cookie and ability to being changed
JS
I am doing a sorting on div , but unable to perform a sorting . I am using jQuery.fn.sortElements . below is the html . Below is the jquery code , I have placed an alert to see the result but nothing happens.Any help is very much appreciated
< div id= '' sortList '' > < div class= '' list '' style= '' display : block ; '' > < a onclick= '' openInfoWindow ( `` 10 '' ) ; return false ; '' href= '' # '' > < /a > < div class= '' imgClass '' > < a onclick= '' openInfoWindow ( `` 10 '' ) ; return false ; '' href= '' # '' > < img class= '' innerImg '' alt= '' '' ...
sorting is not performing in jquery
JS
I have this function : When user choose countrie i call this function but i want to display on start first element from that list ... With this line i get `` Please select '' but i want first element from list : If i comment this line i get blank ... any help ?
function LoadRegions ( ) { var region = $ ( ' # RegionID ' ) ; var url = `` /Account/GetRegions '' ; $ .getJSON ( url , { countryId : $ ( ' # CountryID ' ) .val ( ) } , function ( response ) { // clear and add default ( null ) option //region.empty ( ) .append ( $ ( ' < option > < /option > ' ) .val ( `` ) .text ( 'Ple...
How to print first element from dropdown list on change ?
JS
I have a problem with JavaScript.Inside my Array I have some objects and I tried to load all of them inside some Elements , Problem is when I tried return my Elements inside `` for '' and set objects for each one it 's not work , I mean it just return last one with data and other box ( elements ) are empty This is my J...
var dataStore = [ { fname : `` Keira '' , lname : `` Mayo '' , yold : 30 } , { fname : `` Isaac '' , lname : `` Moses '' , yold : 20 } , { fname : `` Edwina '' , lname : `` Serena '' , yold : 34 } , { fname : `` Tiana '' , lname : `` Cheryl '' , yold : 26 } , ] ; var boxShow = ` < div class= '' box '' id= '' boxMsg '' ...
Problem load data inside element in JavaScript
JS
I would like to iterate over some data like this : ( a ) and ( b ) [ and c , d , e ... ] would also use the object `` item in val.items '' , but { { item.ingredients } } is not a valid expression there , because it is out of the < td > with the object that I want to use to create more columns.Example of what it would l...
< table > < tr ng-repeat= '' ( k , val ) in items '' > < td > { { k } } { { val.style } } < /td > < td ng-repeat= '' ( k2 , item ) in val.items '' > { { item.title } } < /td > < td > { { item.ingredients } } < /td > < -- ( a ) < td > { { item.moreInfo } } < /td > < -- ( b ) < /tr > < /table >
Irregular repetitions in table using JavaScript and Angular.JS
JS
Hey I am doing a small project using react-app and I have been trying all day to create export for this module . I have installed it with npm , and i want to edit it so i can import and use it in my app.jsI have tried to define `` reddit '' using class\function\let and use either : And eitherAnd trying to check with a ...
export defaultmodule.exports import reddit from 'reddit.js ' ; var reddit = require ( 'reddit.js ' ) ; console.log ( reddit.hot ( 'cats ' ) ) ; Uncaught TypeError : reddit.hot is not a function
How to define export for a module in javascript ?
JS
I was going through the code of react-jsonschema-form.I came across following lines which I am unable to comprehend.How is content within the first bracket a function to which arguments ( schema , props.formData etc . ) are passed ?
var formData = ( 0 , _utils.getDefaultFormState ) ( schema , props.formData , definitions ) ;
Unable to understand javascript syntax
JS
I would like that in my webpage the user would be able to upload images.When the user clicks on a particular div , image , button or whatever , a Browse Dialog will be open . Similar to this : But the default folder where the images usually are stored usually change between OS and languages . I would like that on this ...
document.getElementById ( 'buttonFile ' ) .onclick = function ( ) { document.getElementById ( `` file '' ) .click ( ) ; } # file { display : none ; } < input type= '' file '' id= '' file '' > < button id= '' buttonFile '' type= '' button '' > Open File Dialog < /button >
Is there a way to detect default images folder via Javascript ?
JS
My understanding of the < < bitwise left operator in JS ( ES6 ) is that the void to the right is filled with zeros.Empirically , however , I notice that in both V8 and JSC , the set bits seem to suddenly reappear if we shift by 64 or more . This is counter to my expectation , which was that larger shifts would indefini...
( 255 < < 64 ) .toString ( 2 ) //- > `` 11111111 ''
Are bitwise left shifts in JavaScript ES6 ( < < ) cyclical above a shift of 63 ?
JS
Consider the following snippet : I was surprised to see that thing.constructor​ is Object ( ) . ( See fiddle here . ) Why is n't thing.constructor the function f ? ​
​f = function ( ) { } ; f.prototype = { } ; thing = new f ;
Why is the constructor not the constructing function ?
JS
I 'm trying to make a form using Material UI and React . This is what I have so far : The result is the following screenshot : But wait ! Can you see that ? The Button height and the TextField height are just so slightly misaligned ! ( By 2.5px I think ) . Is there any way to fix this ? This is better than earlier , wh...
import React from 'react'import { Button , TextField } from ' @ material-ui/core'import AddIcon from ' @ material-ui/icons/Add'import PropTypes from 'prop-types'class AddItem extends React.Component { state = { text : `` } handleChange = e = > { this.setState ( { text : e.target.value } ) } render ( ) { return ( < form...
How to make the Button and TextField pitch perfect ?
JS
According to the ECMA script standard , the following code should return true , but it does n't : Section 11.9.3 says : If Type ( x ) is either String or Number and Type ( y ) is Object , return the result of the comparison x == ToPrimitive ( y ) . Then , section 8.12.8 says that ToPrimitive retuns the result of the va...
d = new Date ( ) ; d.setTime ( 1436497200000 ) ; alert ( d == 1436497200000 ) ; alert ( d.valueOf ( ) == 1436497200000 ) ;
Equality comparison between Date and number does n't work
JS
Say I have an existing object , a , and a prototype b. I want to make a new object , c , with the values of a , but the prototype of b . Is there a nicer way than the following : Edit : Is Object.setPrototypeOf better or worse than the question solution ?
function Copy ( object ) { Object.assign ( this , object ) ; } Copy.prototype = Object.create ( b ) ; var c = new Copy ( a ) ;
JavaScript Object.create style with existing object
JS
I am working through a book that is all about functional javascript . In that book , there is the following bit of code : I understand this as going through each property of an object then asking IF that object has that property then running a provided function.What I do n't understand is how the if does anything . Wo ...
const forEachObj = ( obj , fn ) = > { for ( let prop in obj ) { if ( obj.hasOwnProperty ( prop ) ) { fn ( prop , obj [ prop ] ) ; } } } ;
Clarify my understanding of a bit of JavaScript
JS
I have made a countdown clock for quiz module so whenever the counter ends up I get a negative value . After the end of the timer I am getting -1 : -1 and I want it as 00:00.I thought there would be an error in the total time but I am not able to figure out the errorI have tried this logic but it 's not workingMy HTML ...
< script > function getTimeRemaining ( endtime ) { var t = Date.parse ( endtime ) - Date.parse ( new Date ( ) ) ; var seconds = Math.floor ( ( t / 1000 ) % 60 ) ; var minutes = Math.floor ( ( t / 1000 / 60 ) % 60 ) ; var hours = Math.floor ( ( t / ( 1000 * 60 * 60 ) ) % 24 ) ; var days = Math.floor ( t / ( 1000 * 60 * ...
How to avoid negative value in clock counter
JS
I have a grid of 3d boxes with only two faces ( front and bottom ) . Each box has its own perspective . On hover , box rotates ; bottom face faces the front . For example : Now , the problem with this setup is the overlaps among boxes . I can get rid of the overlaps manually , and to do that I need to do following chan...
.grid { display : flex ; flex-direction : row ; flex-wrap : wrap ; width : 1000px ; margin : 50px auto ; } .box-wrapper { width : 25 % ; height : 250px ; perspective : 1000px ; } .box { width : 100 % ; height : 100 % ; position : relative ; transition : transform .5s ; transform-style : preserve-3d ; } .box .face { wid...
Grid of 3d boxes ( only two faces )
JS
I wrote a factory of Angular . There was a critical error for me . I wandered to fix it . Finally , I cleared this problem ... without reason . So I need clear description of below code problem.Here is my code A : And another B is : And the error part is : code B works well . code A made error message `` UserServicePro...
angular .module ( 'BinD ' , [ 'ngSails ' ] ) .factory ( 'UserService ' , function ( $ sails ) { ... } ) ; ( function ( angular ) { 'use strict ' ; angular .module ( 'BinD ' , [ 'ngSails ' ] ) .factory ( 'UserService ' , function ( $ sails ) { ... } ) ; } ) ( angular ) ; ( function ( angular ) { 'use strict ' ; angular ...
Difference between angular as global variable and parameter ?
JS
I 'm developing a little function for my site where a sign in form is automatically shown in the navbar when the site is opened up , but only if a certain cookie has not been set . Then , after 10 seconds has passed , the form will disappear.It is also supposed to stay open if the user has selected one of the form inpu...
$ ( document ) .ready ( function ( ) { // hide sign in form function hideForm ( ) { // function for updating elements $ ( `` # darknet-login-nav '' ) .css ( `` display '' , `` none '' ) ; $ ( `` .index-outer '' ) .css ( `` height '' , `` 100px '' ) ; $ ( `` .index-inner '' ) .css ( `` width '' , `` 438px '' ) ; $ ( `` ...
hide sign in form after 10s if cookie not set and no inputs are selected
JS
My JS Code does not work for a modal with a form that is loading from an ajax-call to php side.I think I have to call the function like the following : How should I change the original code into this , can someone help and explain it to me ? Using only the $ ( ' # tags ' ) does not work.Additionally , I have to change ...
$ ( document ) .on ( 'click ' , ' # tags ' , function ( ) $ ( ' # tags ' ) .on ( { click : function ( e ) { e.preventDefault ( ) ; alert ( 'geklickt ' ) ; } , mouseenter : function ( e ) { alert ( 'mouse enter ! ' ) ; } } ) ; $ ( document ) .ready ( function ( ) { bookIndex = 0 ; $ ( ' # bookForm ' ) // Remove button c...
How .on works for $ ( document )
JS
I wrote simple JavaScript to show hidden < div > after clicking another < div > . Everything works fine however when clicking checkbox in that < div > the hidden one appears and hides instantly.Fiddle : https : //jsfiddle.net/mamzj4tw/
$ ( document ) .ready ( function ( ) { $ ( ' # click1 ' ) .click ( function ( ) { if ( $ ( ' # hidden1 ' ) .is ( ' : hidden ' ) ) { $ ( ' # hidden1 ' ) .show ( 500 ) ; } else { $ ( ' # hidden1 ' ) .hide ( 500 ) ; } } ) ; } ) ; .divCell { width : 500px ; height : 35px ; margin : 2px 0 ; display : inline-block ; backgrou...
Showing/hiding < div > with JavaScript
JS
I 'm sure this is super simple , and I do n't really want a complete solution , but pointing in the right direction as I 'm learning.I have : and the goal is to make it look like this , grouping like items : My following code arranges , and groups fine . I push the temp to my Group array . But when I reset my `` tempAr...
let randomArray = [ 1,2,4,591,392,391,2,5,10,2,1,1,1,20,20 ] ; [ [ 1,1,1,1 ] , [ 2,2,2 ] , [ 10 ] , [ 20,20 ] , [ 391 ] , [ 392 ] , [ 591 ] ] // My SOlutionlet randomArray = [ 1,2,4,591,392,391,2,5,10,2,1,1,1,20,20 ] ; let tempArray = [ ] ; let groupArray = [ ] ; function cleanTheRoom ( arr ) { let ascendingArray = arr...
Adding arrays to an array of arrays
JS
I implmented Singleton by assigning instances to the constructor.I want to be implemented in singleton for each of the three classes Parent , Child , and Child2 . But there is a problem , when I instantiate Parent class before other classes.I tried to come up with good idea , but fail . Is there any way I can solve it ...
const instance = Symbol ( 'instance ' ) ; class Parent { number ; constructor ( ) { const Class = this.constructor ; if ( ! Class [ instance ] ) Class [ instance ] = this ; return Class [ instance ] ; } set_number ( number ) { this.number = number ; } } class Child extends Parent { test ( ) { } } class Child2 extends P...
How to implement singleton pattern in the following situation ?
JS
So , the code above outputs > > > 19 20 times . To keep i at it 's iteration value I 'm using a closure : What 's the problem ? The problem is loop control statements , continue ; I can do with return ; but for those times when I need break ; code gets counter-intuitive when others try to read it.So what can I do ?
for ( var i=0 ; i < 20 ; i++ ) setTimeout ( function ( ) { console.log ( `` > > > `` +i ) ; } , i*100 ) ; for ( var i=0 ; i < 20 ; i++ ) ( function ( i ) { setTimeout ( function ( ) { console.log ( `` > > > `` +i ) ; } , i*100 ) ; } ( i ) ) ;
Better way to seize values inside loops
JS
I am using jQuery to hide a div via hide ( ) .Then when a link is clicked it will show the div , but for some reason it will not stay.it will show for a ms then disappear.HTMLjQuery
< div id= '' introContent '' > < h1 id= '' introText '' > Welcome < /h1 > < p id= '' introParagraph '' > I create < strong > Responsive < /strong > , < strong > Interactive < /strong > , < strong > Beautiful < /strong > Mobile ready Websites . Every Website is created from scratch for each client so no Two Projects are...
why jQuery show ( ) is not working ?
JS
I have array of object : I want to sort it like this , Sort By name ascending , and then no ascending and then by size1 if it not null.At first , I can sort it by name and no , but after that I do n't know how to sort by size1 or size2 . It should sorted by size1 first if it is not null.Here is my code to sortExpected ...
var a = [ { `` name '' : `` BBB '' , `` no '' : 2 , `` size1 '' : [ 3 ] , `` size2 '' : null } , { `` name '' : `` AAA '' , `` no '' : 5 , `` size1 '' : null , `` size2 '' : [ 1 ] } , { `` name '' : `` BBB '' , `` no '' : 1 , `` size1 '' : [ 2 ] , `` size2 '' : null } , { `` name '' : `` AAA '' , `` no '' : 4 , `` size...
Javascript - How to sort array of object by 3 different attributes type ? ( String , Integer , Boolean )
JS
Whenever we load .html files serving some controller in angular.Does angular makes an ajax call to retrive that html.Like this piecec of code.I mean to ask while fetching signin.htmlIs an ajax call made ? Or are they loaded as normal resources ? If an ajax call is made where can i find some documentation written about ...
.state ( 'home ' , { url : '/ ' , templateUrl : '/Modules/Signin/signin.html ' , controller : 'SigninCtrl ' } )
Loading Angular View
JS
I know that is a common way to solve the common problem `` Push this element to the end of array if the array exists , and if it does n't exist , initialize the array and then push the element '' But how does the syntax break down ? Here 's how I see it : The presence of the || means that whatever is to the left and ri...
( M [ key ] || ( M [ key ] = [ ] ) ) .push ( elem ) ;
How does `` ( M [ key ] || ( M [ key ] = [ ] ) ) .push ( elem ) ; `` work ?
JS
I apologize if my terminology is incorrect — this is definitely not my area of expertise.I am looking to make a < select > list from a json file , and group the entries in < optgroup > s by a key . I have successfully been able to list all the entries in a select , but do n't know how to loop through and nest items und...
[ { `` Type '' : `` Overdrive '' , `` Brand '' : `` Chase Bliss '' , `` Name '' : `` Brothers '' , `` Width '' : 2.75 , `` Height '' : 4.77 , `` Image '' : `` public/images/pedals/chasebliss-brothers.png '' } ] window.RenderPedals = function ( pedals ) { for ( var i in pedals ) { var $ pedal = $ ( `` < option > '' + pe...
List array contents grouped by key
JS
I am creating a `` whack-a-mole '' style educational game for children where a question is given and they have to click on the right appearing number . For example when a sum like `` 2+2 '' is given the child must wait for a `` 4 '' to appear and click it . The question changes every time the correct answer is hit , bu...
function correctlabels ( ) { switch ( Math.ceil ( Math.random ( ) * 9 ) ) { case 1 : check = sum1 ; $ ( ' # target ' ) .html ( ' 0 + 1 = ? ' ) ; break ; case 2 : check = sum2 ; $ ( ' # target ' ) .html ( ' 1 + 1 = ? ' ) ; break ; case 3 : check = sum3 ; $ ( ' # target ' ) .html ( ' 2 + 1 = ? ' ) ; break ; case 4 : chec...
change target answer
JS
I try to make a version of `` tic tac toe '' with AngularJS and be as minimalistic as possible . The only solution for my problem is to assign every button a unique ID ( f+i ) .HTMLJavaScript
< table > < tr ng-repeat= '' f in [ 5,10,15 ] '' > < ! -- numbers chosen for unique combos -- > < td ng-repeat= '' i in [ 0,1,2 ] '' > < button ng-click= '' toTrue ( ) '' > < div > { { getXO ( ) } } < /div > < /button > < /td > < /tr > < /table > $ scope.XObool=false ; $ scope.toTrue = function ( ) { if ( ! $ scope.XOb...
How to make a custom HTML id by evaluating an expression
JS
Edit : Visit https : //jsfiddle.net/DTcHh/40740/ for the final solution ! Update : This question is a followup ! I have a div with an `` add question '' ( Bootstrap ) radio button . My intention is , that the div in which the button is placed should be copied and placed underneath when the mentioned button is clicked :...
< div id= '' singleQuestionModule '' > < div class= '' question-wrapper '' > < form class= '' form-group '' > < div class= '' d-flex justify-content-center '' > < fieldset class= '' form-group row '' > < legend class= '' col-form-legend col-sm-10 '' > < /legend > < div class= '' form-group row '' > < div class= '' inpu...
How do I create a function which copies and inserts it 's own div ?
JS
I was trying to work on a rainbow-pen drawing canvas , but whenever I draw , the lines appear dotted.Only when I move really slowly , does it appear properly.The 'mousemove ' event listener , is n't really being able to detect fast changes or is there some other issue in my code ? Also , here is the codepen link , if a...
const canvas = document.querySelector ( ' # draw ' ) ; canvas.width = window.innerWidth ; canvas.height = window.innerHeight ; var ctx = canvas.getContext ( `` 2d '' ) ; ctx.lineWidth = 50 ; ctx.lineCap = `` round '' ; ctx.lineJoin = `` line '' ; ctx.strokeStyle = 0 ; let hue = 0 ; var [ x , y ] = [ 0 , 0 ] ; let paint...
Drawing lines on canvas are dotted
JS
I have a slider that I 've been trying to get working . It 's demo was 3 slides , but I am trying to add 4 . When I add it in , the 4 item is eitherIn the back permanentlyUnder the right-sides imageI 'm not quite sure how I can fix this , if there is a way.To help describe what I 'm looking for , imagine the below is m...
[ back img ] [ left img ] [ right img ] [ front img ] < div class='p_slider ' > < div class='p_slider__item ' > < img src='https : //s3-us-west-2.amazonaws.com/s.cdpn.io/217233/iwatch1.png ' > < /div > < div class='p_slider__item ' > < img src='https : //s3-us-west-2.amazonaws.com/s.cdpn.io/217233/iwatch2.png ' > < /di...
Ca n't get slider to use 4 items ?
JS
I am working on alpha.dubaiexporters.com . There is a search Panel containing two inputs Keyword and Categories . I wanted to validate Keyword part.If the user entered less than three characters and clicked on Search button then the clientside message should be displayed saying the entered input should be more than 3 c...
< input type= '' text '' id= '' txtkeyword '' name= '' s '' runat= '' server '' autocomplete= '' off '' > < asp : Button ID= '' Search '' class= '' dt-header-search-submit dt-button dt-button-danger '' style= '' top:0px ; width:226px ; height:70px ; '' Text= '' Search '' runat= '' server '' onclick= '' doit '' OnClient...
Not getting the clientside message after clicking on Search button
JS
I have two buttons , when a user clicks on them it gets underlined . However , I 'd like the .underline to be animated/glide horizontally to the button that is being clicked on.Demo : https : //jsfiddle.net/ds1wr736/11/As of right now , the .underline just appears and disapears when a button is clicked . How can I anim...
function switchTab ( tab ) { if ( tab === 1 ) { document.getElementById ( `` tab2 '' ) .classList.add ( `` underline '' ) ; document.getElementById ( `` tab1 '' ) .classList.remove ( `` underline '' ) ; } else if ( tab === 2 ) { document.getElementById ( `` tab1 '' ) .classList.add ( `` underline '' ) ; document.getEle...
How to properly animate a bar gliding ?
JS
I have 2 arrays : and I want them to be sorted by the numerical array : while its actually not important if `` b '' or `` d '' comes first ( they both have 4 in this example ) I found many questions about this online but none of them worked for me can anyone help me with that ?
[ 2 , 4 , -2 , 4 , 1 , 3 ] [ `` a '' , `` b '' , `` c '' , `` d '' , `` e '' , `` f '' ] // output [ -2 , 1 , 2 , 3 , 4 , 4 ] // < -sorted by numerical order [ `` c '' , `` e '' , `` a '' , `` f '' , `` b '' , `` d '' ] // sorted exactly the same order as the first array
Sort one array the same way as another array JavaScript
JS
I have 2 select statement which the first select is populated by my first webservice request . User selects the desired data in the first select , in which will trigger the onChange method to retrieve first select object , run webservice again to retrieve another set of datas and populate the 2nd select statement . HTM...
< div class= '' input-label '' > Select Kittens : < /div > < selectng-model = '' options '' ng-options = '' option.name for option in options '' ng-change= '' onChange ( options ) '' > < option > -- < /option > < /select > < br > < div class= '' input-label '' > Select Age : < /div > < selectng-options = '' detail.age ...
Unable to populate 2nd select statement
JS
I have a function something like this : So now I do it : It works fine but I have a problem . Let me explain . I want it to execute same as now till with no space between.For example : But I want it to change the text even with no spaces . How can I do that ?
var exchange = function ( code ) { var ref = { 'one ' : ' 1 ' , 'two ' : ' 2 ' , 'three ' : ' 3 ' } ; return code.split ( ' ' ) .map ( function ( a ) { return a.split ( ' ' ) .map ( function ( b ) { return ref [ b ] ; } ) .join ( `` ) ; } ) .join ( ' ' ) ; } ; var strg = `` one two three '' ; alert ( exchange ( strg ) ...
How to replace characters or words in a string using javascript even with no space between them ?
JS
i have many data like this : but i want to use the 3.2 part , what can i do using jquery , thanks
3.23214215
simple way to make 3.2242143 to 3.2 using jquery
JS
I need to make the following ( below ) function call to give the same result in both situations : I tried the following but it 's not working : Any suggestions ?
sum ( 5,4 ) ; // 9sum ( 5 ) ( 4 ) ; // this should also print 9 function sum ( x , y ) { var a = x ; var b = y ; if ( y == undefined & & y == `` ) { return function ( a , b ) { return a +b ; } } else { return a +b ; } }
how to get the same result by using function and closure together in javascript
JS
When I wroteThe result is the c object has a `` get a '' and `` set a '' property.Why ? Tested in Chrome and Firefox .
var c = { get a ( ) { } } ;
Why i can write a object like `` c = { get a ( ) { } } '' ?
JS
In my react application , a user logs in and then directed to his/her dashboard upon authentication . In order to display all the data of the user in the dashboard I have a separate file in which there is a function called getUserData ( ) which dispatches all the actions of the dashboard components and then getUserData...
const token = localStorage.getItem ( 'token ' ) store.dispatch ( { type : USER_LOADING } ) ; if ( token ) { store.dispatch ( { type : USER_AUTHENTICATED } ) } class App extends Component { componentDidMount ( ) { store.dispatch ( loadUser ( ) ) ; } render ( ) { return ( < Provider store= { store } > < div className= ''...
React and Redux : Dispatching all actions within one function
JS
I am trying to watch a prop in Vue 3 but it is strange that when I destructure it then the watcher does n't work . But without destructuring it works as expected . What am I missing here ? P.S . I am using Vue 3 + ViteThis is not workingBut if I don ’ t destructure it then it works
export default { props : { modelValue : { type : Boolean , default : false , } , } , setup ( { modelValue } , context ) { watch ( ( ) = > modelValue , ( newValue , oldValue ) = > { console.log ( newValue ) } ) } , } setup ( props , context ) { watch ( ( ) = > props.modelValue , ( newValue , oldValue ) = > { console.log...
Vue 3 watch doesn ’ t work if I watch a destructured prop
JS
I have something like this : I wonder if exist shorter syntax to use `` this.selectedItem.label '' only one .
if ( this.selectedItem.label == `` str1 '' || this.selectedItem.label == `` str2 '' || this.selectedItem.label == `` str3 '' || this.selectedItem.label == `` str4 '' ) { }
Shorter syntax of conditional or against many Strings
JS
I have a function that searches through a tree of folders and finds the selected folder 's parent folder.Here is the function.When I call this with this.getParentFolder ( rootFolder , childFolder ) ; It simply just gives me : Uncaught TypeError : this.getParentFolder is not a functionWhy is this ? In the same file I ca...
getParentFolder : function ( searchroot , childFolder ) { searchroot.subfolders.forEach ( function ( folder ) { if ( folder.key == childFolder.key ) { return searchroot ; } else { if ( folder.subfolders ) { return this.getParentFolder ( folder , childFolder ) ; } } } ) ; }
Can not call my recursion function in javascript/Polymer
JS
In the current software I am working on , I 'm seeing this pattern quite extensively and it seems that they 're trying to avoid return statements as much as possible . Even at some places in the code this is taken almost to the extreme.I 've somehow heard a long time ago that return statements should be minimized or av...
if ( err ) { if ( err.message ) { message = err.message ; } else { if ( err.errorCode ) { message = err.errorCode ; } else { message = `` Unknown error '' ; } } } else { message = `` Unknown error . `` ; } deferred.reject ( message ) ; if ( ! err || ( ! err.message & & ! err.errorCode ) ) { deferred.reject ( `` Unknown...
should we avoid/minimize using return statements in javascript flow control
JS
I am reading an implementation of Array.prototype.some on developer.mozilla.orgIt contains this intruiging piece of code : Why is it calling len = t.length > > > 0 instead of len = t.length ? What difference does > > > 0 make ?
var t = Object ( this ) ; var len = t.length > > > 0 ; for ( var i = 0 ; i < len ; i++ ) {
In Javascript , what is the effect of ' > > > 0 ' on a variable ?
JS
Are comments literally just stripped out of your source before parsing , or can they count as linebreaks and disrupt continuity in certain contexts ? You know , cause they say whitespace is `` safe '' and `` insignificant '' or whatever , but we all know there are exceptions to that . Are comments actually safe ?
'foo'.replace ( /f/ , ' b ' ) //f- > b .replace ( /o/ , ' a ' ) //o- > a .replace ( /o/ , ' r ' ) /*o- > r*/ ; 'foo'.replace ( /x/ , /*matches `` x '' */ ' y ' ) ; var foo = ( true ! == false ) ? // bikeshed 'bar ' : /*if they 're equal , which they wo n't be , we 'll want 'baz'*/ 'baz ' ;
Are comments 100 % safe on all the major environments ?
JS
I have following function : I wanted ro refactor it and rewrite it so : but in console I see that Uncaught ReferenceError : data is not definedHow to refactor it right ?
$ .getJSON ( 'getTerminalinsideCircle.json ' , { centerLatitude : adressMarker.getPosition ( ) .lat ( ) , centerLongitude : adressMarker.getPosition ( ) .lng ( ) , radius : radius/1000 } , function ( data ) { $ .each ( data , function ( key , val ) { ... . } ) } ) $ .getJSON ( 'getTerminalinsideCircle.json ' , { center...
Why does variable is not defined ?
JS
I am currently writing a piece of JavaScript that uses base 36 encoding.I came across this problem : Appears to return `` welcomebacg '' .I tested this in the Chrome developer 's console and Node.js with the same result.Is there any logical explanation for this result ?
parseInt ( `` welcomeback '' ,36 ) .toString ( 36 )
Why JavaScript base-36 conversion appears to be ambiguous
JS
I 'm using transform : rotate ( ) ; to rotate content in & out of view , however , each body of text is at a different position when it comes into view . So when you click the next button on my demo if you look at the border the contents are in different positions.When the next button is clicked the wheel rotates equal...
// Page load transform start , settersvar degree = 0 ; var itemStart = $ ( '.wheel ' ) .find ( '.item-one ' ) .addClass ( 'item-active ' ) ; var itemNext = $ ( '.wheel ' ) .find ( '.item-four ' ) .addClass ( 'item-prev ' ) ; // On click $ ( '.next ' ) .click ( function ( ) { var wheel = $ ( '.wheel ' ) ; // Increment r...
When using transform rotate stop shifting content
JS
For example , I have the following html : And , i want to style only li elements which have value = 1.I tried this in jQuery and it works , but i want to know if there is a better way to perfom this.My approach :
< ul > < li > 1 < /li > < li > 2 < /li > < ul > < li > 1 < /li > < ul > < li > 1 < /li > < li > 2 < /li > < /ul > < li > 2 < /li > < /ul > < /ul > < ul > < li > 1 < /li > < li > 2 < /li > < /ul > < ul > ` enter code here ` < li > 1 < /li > < li > 2 < /li > < /ul > $ ( `` ul li '' ) .each ( function ( ) { if ( $ ( this ...
Styling specific < li > element in unordered list < ul >
JS
I want to replace JS array property values using another JS array . I have explained as below.Expected output : We need to check all arr1 element where equal new_arr.code to arr1.code and compare dis and note properties . If arr1.dis not equals new_arr.dis then arr1.dis value should be replaced by new_arr.dis . This is...
const arr1 = [ { code : `` XXY '' , dis : `` cont1 '' , note : `` Note for cont1 '' } , { code : `` AAW '' , dis : `` cont2 '' , note : `` Note for cont2 '' } , { code : `` TTR '' , dis : `` cont5 '' , note : `` Note for cont5 '' } , { code : `` MMN '' , dis : `` cont10 '' , note : `` Note for cont10 '' } ] const new_a...
How to replace JS array property values using another JS array
JS
Let 's say I need to list an amount of followers of each user who contribute to some repository ( using JavaScript ) . First , I use this : I get the JSON list of users , but there 's no information about an amount of followers of each of them . I thought I 'd ask for it separately ( in a loop ) , using `` url '' like ...
$ .ajax ( { headers : { Authorization : `` Basic `` + auth } , type : 'GET ' , url : 'https : //api.github.com/repos/ [ reponame ] /angular/contributors ' , dataType : 'json ' , success : function ( data ) { repositories = data ; outputPageContent ( ) ; } } ) ;
GitHub : How to avoid exceeding search limit while searching for account 's details of users who contribute to some repository ?
JS
Infinite loop on setting stateI have a array of objects testData , wich i want to filter trough to get another array with results : Code below works almost good but i can not set the return value to a state.When i try to useState in a function it gives me infinite loop . How can i set state of historyResult ( ) return ...
const testData = [ { time : `` 2020-01-23T13:16:53+01:00 '' , amount : `` 0.010000000000000000 '' , txid : `` 7b1f6aa63910618913c1c1c2902671d2e4f074a8c77ecfd3d16994a05fbf952d '' } , { time : `` 2020-01-31T09:09:13+01:00 '' , amount : `` -0.012739560000000000 '' , txid : `` 7df38cb2d7538f794d725e4c7e68a3e1e7ee6fd570c357...
React hooks , set return value of a function to state causes infinite loop
JS
I ’ ve programmed a function that rotates objects around a main object , like how planets rotate around the sun.I 'm trying to dynamically add new planets in my little solar system by a simple click of a button . They are all SVG elements . I 'm having trouble working out how I can dynamically generate new elements tha...
var objectX = `` black '' ; function addObject ( ) { objectX = `` blue '' ; } function rotation ( coorX , coorY , object ) { object.side += ( 1.0 / object.speed ) ; var ang = object.side * 2.0 * Math.PI / 180.0 ; var r = object.spin ; return { x : Math.cos ( ang ) * r - Math.sin ( ang ) * r + coorX , y : Math.sin ( ang...
Dynamically add new elements in function
JS
I 'm not really a javascript noob at all , although in my whole life I 've never came across this , but am I right in assuming that javascript must assign functions before running anything or something ? In all my experience , I expected this to return 'undefined ' , but obviously it returns 'function'.Is someone able ...
function bar ( ) { return foo ; foo = 10 ; function foo ( ) { } var foo = '11 ' ; } alert ( typeof bar ( ) ) ;
Are functions defined regardless of the order ?
JS
I am getting into programming with javascript and using Promises , right now using Q.js . I have finally gotten to a point where I understand what I am doing , but am having a difficult time with a specific behavior.I have one situation where I have reasonably similar code repeated several times . It basically goes lik...
{ // start var deferred = Q.defer ( ) ; // do something { deferred.resolve ( ) ; } return deferred.promise ; } { var list = [ ] ; queue = function ( f ) { var deferred = Q.defer ( ) ; list.push ( f ( deferred ) ) ; return deferred.promise ; } { queue ( function ( deferred ) { // do some work // we want the deferred her...
Difficulty wrapping a javascript behavior and holding it for later
JS
I 've been worrying about this for a while and I ca n't realize what 's really happening . Explanation in code comments . There are 2 versions of an application , one of them throws weird results and the second one does the expected work . I 'm not sure if it has something to do with ajax call , or an anonymous functio...
var id = `` test1 '' ; $ .post ( `` http : //fiddle.jshell.net/echo/json/ '' , { `` data '' : `` data '' } , function ( a ) { alert ( id ) ; // will throw undefined var id = `` test2 '' ; alert ( id ) ; // will throw `` test2 '' as expected } ) ; $ .post ( `` http : //fiddle.jshell.net/echo/json/ '' , { `` data '' : ``...
Very weird behavior when using `` var '' keyword in an ajax request
JS
By mistake , an URL was pasted into a JavaScript snippet . Reduced to a minimum , it looked roughly like this : It was overlooked for quite some time , because it did not produce an error . Why is that ? Why does this function still run without erroring ?
function ( ) { /* a bunch of code */ http : //www.stackoverflow.com /* a bunch of code */ return `` it still works '' ; }
Why is a URL in the middle of a function not causing an error ?
JS
I know that operands of bitwise operation are treated as 32-bit integers in Javascript . So I thought that it would be zero 'd out if I do < < 32 on integer values . But it worked as if it 's < < 0 . For what reason is it worked in that way ? What exactly does shift operation whose right operand is over 31 do , in Java...
0b00000000000000000000000000000001 < < 32 // 10b00000000000000000000000000000001 < < 33 // 20b00000000000000000000000000000001 < < 34 // 40b00000000000000000000000000000001 > > 30 // 00b00000000000000000000000000000001 > > 31 // 0// Something weird is happening ... ... .0b00000000000000000000000000000001 > > 32 // 10b0...
What exactly does shift operation whose right operand is over 31 do , in Javascript ?
JS
What is the quickest way to compare two arrays and return a third array containing the values from array2 where the associated values from array1 are true ? The result should be :
const array1 = [ true , false , false , true ] ; const array2 = [ ' a ' , ' b ' , ' c ' , 'd ' ] ; const result = [ ' a ' , 'd ' ] ;
Compare true/false array with other array
JS
I am looking at this fiddle : http : //jsfiddle.net/kDs2Q/45/Is there a way to layer the divs/line in a way so that the line will be behind the other divs ? I want to be able to draw the line from the center of one div to the center of the other but not see the line cross over the actual boxes.This is how I would to th...
var off1 = getOffset ( div1 ) ; var off2 = getOffset ( div2 ) ; var x1 = off1.left + off1.width/2 ; var y1 = off1.top + off1.height/2 ; var x2 = off2.left + off1.width/2 ; var y2 = off2.top + off1.height/2 ;
Drawing Lines Behind Divs
JS
Following on from my previous question . I made a helper function ( see below ) , to insert elements into the DOM . Part of the function uses 'instanceof ' to determine if 'this ' element is an instance of an HTMLMediaElement and determines the source attribute by way of the argument 'elemSrc ' . My question : Is there...
function insertElem ( numberOfElems , elemTag , elemId , elemClass , parentSelector , elemSrc ) { /* * numberOfElements : - Pass in a whole integer . * elemTag : - Pass in the element tag type ( inside `` '' or `` ) . * elemId : - Pass in a name for the element id ( inside `` '' or `` ) , an integer is appended to the ...
Check if an HTML element is expecting a source attribute
JS
Suppose I have a symbol such as const sym = Symbol ( 'foo ' ) ; . Now , is there a way to get the value foo from that symbol without relying on string manipulations ? I expected sym.toString ( ) to return 'foo ' but it returns Symbol ( foo ) .UpdateI settled with this hacky solution , until I find a better one : )
const key = Symbol.keyFor ( sym ) || ( sym = sym.toString ( ) , sym.substring ( 7 , sym.length - 1 ) ) ;
Is it possible to get the description value of a defined Symbol in JavaScript ?
JS
I have a question is it possible to declare comment inside of ng-class
ng-class= '' { 'test ' : true , 'test1 ' : true , //some comment 'test2 ' : true } ''
Is it possible to declare comment inside of ng-class
JS
I need to get only 16 ( or other small number ) of possible hashes from string for color-coding contacts based on contact name.I had try to get a crc32 hash and then take a first symbol , which is hex digit : However , I have doubts about good distribution of such method . How can I get small and determined amount of v...
$ contact = 'Robin Hood ' ; $ colors = [ ' 0 ' = > 'F8BBD0 ' , ' 1 ' = > 'E1BEE7 ' , ... ' e ' = > 'D7CCC8 ' , ' f ' = > 'CFD8DC ' , ] ; $ firstLetter = hash ( 'crc32 ' , $ contact ) [ 0 ] ; return ' # ' . $ colors [ $ firstLetter ] ;
Hash/digest with determined ( small ) amount of variants
JS
A developer recently told me I could make ajax requests to php pages , have them return javascript methods and then have the client execute those methods . How is this done ? A link to a relevant resources would be great too.Edit5 years wiser , I would now try pretty hard never to do this . Any mechanism of this kind o...
< script src=/dynamic-script.php ? param1=blah & param2=ayyylmao > < /script >
Return javascript with AJAX
JS
Let 's face this situation : What i 'm trying to do is match lis that either have selector class or have class attribute undefined , something like this : So if I 'm running prevAll ( ) on the .selector2 , it should return 2 list items . If i run it on .selector , it should return the first list item.So is there a way ...
< ul > < li > data < /li > < li class= '' selector '' > data2 < /li > < li class= '' selector2 '' > data3 < /li > < /ul > jQuery ( function ( $ ) { $ ( '.selector2 ' ) .prevAll ( 'li.selector OR li [ class== '' '' ] ' ) ; } ) ;
Find prev ( ) tags with several selectors
JS
It 's kind of hard to explain in words what I 'm looking for without a visual example , so here 's the basic idea : https : //codepen.io/jwiggiff/full/xxwvVbrIn the codepen , if you click the text on the edge of the screen , it moves the current face to cover the entire window . When you click the left or right text , ...
var cube = $ ( '.cube ' ) ; var wrapper = $ ( '.wrapper ' ) ; $ ( document ) .mousemove ( ( e ) = > { if ( ! cube.hasClass ( 'locked ' ) ) { var deltaX = e.pageX - ( wrapper.offset ( ) .left+ ( wrapper.width ( ) /2 ) ) ; var deltaY = e.pageY - ( wrapper.offset ( ) .top+ ( wrapper.height ( ) /2 ) ) ; var rotateY = delta...
How do I remove the bounce effect when translating away from the screen with css transition ?
JS
I am trying to learn how to fetch data inside factory . Currently I am using fetch data with the controllerfactory.jsdetail-poduct.jsproduct-detail.htmlbut when I change the code to move the fecthing inside factory like this factory.jsdetail-product.jsit gives me an error that data is not defined .
angular .module ( 'app ' ) .factory ( 'Product ' , [ ' $ http ' , function ( $ http ) { return { get : function ( ) { return $ http.get ( 'https : //raw.githubusercontent.com/vicariosinaga/learn/master/products.json ' ) .then ( function ( response ) { return response.data ; } ) ; } } ; } ] ) angular .module ( 'app ' ) ...
Fetching data json with factory
JS
I saw this example on mozilla documentation but i do n't understand why.if 0 is a property of trees , i was expecting that trees.0 would return redwood but is a wrong statement . Is a [ 0 ] a way to access the 0 property of the array ? In this case a [ `` length '' ] should also work ( logicaly ) . Can anyone make it c...
var trees = new Array ( `` redwood '' , `` bay '' , `` cedar '' , `` oak '' , `` maple '' ) ; 0 in trees ; // returns true3 in trees ; // returns true6 in trees ; // returns false
How is 0 a property of trees when var trees = new Array ( `` redwood '' , `` bay '' , `` cedar '' )
JS
Can an async generator be somehow broadcast or multicast , so that all its iterators ( `` consumers '' ? subscribers ? ) receive all values ? Consider this example : Iterations `` consume '' a value , so only one or the other gets it.I would like for both of them ( and any later ones ) to get every yielded value , if s...
const fetchMock = ( ) = > `` Example . Imagine real fetch '' ; async function* gen ( ) { for ( let i = 1 ; i < = 6 ; i++ ) { const res = await fetchMock ( ) ; yield res.slice ( 0 , 2 ) + i ; } } const ait = gen ( ) ; ( async ( ) = > { // first `` consumer '' for await ( const e of ait ) console.log ( ' e ' , e ) ; } ) ...
How to `` multicast '' an async iterable ?
JS
I was trying to generate an array of random numbers between 10 and 1000 in descending ordered.This is the code I wrote : When run in the terminal , here are the results I get : new GenerateRandomArray ( ) = > [ 924 , 804 , 79 , 788 , 585 , 451 , 267 , 217 , 153 , 135 ] new GenerateRandomArray ( ) = > [ 869 , 697 , 647 ...
function GenerateRandomArray ( ) { var array = [ ] ; for ( var i = 0 ; i < 10 ; i++ ) { array [ i ] = Math.round ( Math.random ( ) * ( 1000 - 10 + 1 ) + 10 ) ; } return array.sort ( ) .reverse ( ) ; }
Unexpected behavior with random array generation