lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I have a text and block in an animation of an SVG element.Here in my example i simplified everything . I want to have one initial animation and afterwards a hover animation on the block element . The initial animation is fine as it is . ( use chrome to have equals measurements ) . But after the initial animation the us...
.text { font-weight : bold ; opacity : 0 ; transition : all .8s ; animation : showText 3s ease-in-out forwards ; animation-delay : 2s ; } .text : hover { opacity : 1 ; transition : all .8s ; } .block { top : 50px ; left : 50px ; position : absolute ; height : 20px ; width : 20px ; background-color : red ; transition : ...
How to apply a hover effect on an element which has already been handled by an forward animation ?
JS
It is the predominant opinion that built-in Javascript prototypes should not be extended ( or altered in any way ) : Does this rule also apply to ES2015 symbols ? Since symbol is a mix of string ( primitive , immutable ) and object ( identity ) there can be no object property naming conflicts by definition.Normal objec...
Array.prototype.empty = function ( ) { return this.length === 0 ; } // do n't try that const empty = Symbol ( `` empty '' ) ; Array.prototype [ empty ] = function empty ( ) { return this.length === 0 ; } Object.getOwnPropertyNames ( Array.prototype ) .indexOf ( `` empty '' ) ; // -1
Should the extension of built-in Javascript prototypes through symbols also be avoided ?
JS
These 2 expressions do the same thing but which one is safer or even more efficient ? ( Both a getting a cell 's , selectedCell , parent row and indexing into a column on that parent row . )
var indexedCellValue = selectedCell.srcElement.parentElement.cells [ index ] .innerText ; var indexedCellValue = $ ( selectedCell.srcElement ) .parent ( 'tr ' ) .get ( 0 ) .cells [ index ] .innerText ;
Are JQuery selectors safer than DOM properties ?
JS
I have an object with conditional keys . I.e . : I 'm new to TS and I expected this to work : However , I 'm passing this to fetch and the type definition for fetch 's headers is { [ key : string ] : string } . I 'm getting : The only way I could get this to work is type RequestHeaders = { [ key : string ] : string } ;...
const headers : RequestHeaders = { } ; if ( ... ) { headers.foo = 'foo ' ; } if ( ... ) { headers.bar = 'bar ' ; } type RequestHeaders = { foo ? : string , bar ? : string , } ; Type 'RequestHeaders ' is not assignable to type ' { [ key : string ] : string ; } ' . Property 'foo ' is incompatible with index signature . T...
TypeScript optional object key not behaving as expected
JS
I have four files.index.php `` the main page '' with search function that use MySQL databse . and I call the databasethrow javascript , client side.fetch.php `` contain MySQL connections info's.bridge.php to cover fetch file , and I 'm using php code to makethe connection..htaccess file to block any direct access to th...
< script > $ ( document ) .ready ( function ( ) { function load_data ( query ) { $ .ajax ( { url : '' bridge.php '' , method : '' post '' , data : { query : query } , success : function ( data ) { $ ( ' # result ' ) .html ( data ) ; } } ) ; } < ? phpinclude 'fetch.php ' ; ? > < Files ~ `` fetch.php '' > Order deny , al...
How do I make a bridge code between my javascript file and php file to protect MySQL info 's ?
JS
I want to read Data via node red modbus node from a data source . The range is -20000 to 20000 , but the node can not handle negative numbers , so I had to convert them to binary numbers ( DWORD ) , split them in the lower and higher word and convert these words back to integers.For visualisation I want to use the dash...
var lowfunction dec2bin ( dec ) { return ( dec > > > 0 ) .toString ( 2 ) ; } var a = msg.payloadif ( a > = 0 ) { a = dec2bin ( a ) ; a = parseInt ( a,2 ) ; } else { a = dec2bin ( a ) ; a = a.substr ( 16 ) ; a = parseInt ( a,2 ) ; } low = { payload : a } ; return low ;
How can I convert negative binary number to int ?
JS
My document looks like this : Basically the background is one full-screen , transparent div . There are couple problems ... if I just create the background div and do n't apply any z-index to it , it ends up being on top of everything , and I can not click on the box . If I set the z-index of the background div to be b...
var x = document.getElementById ( `` bg '' ) ; x.addEventListener ( `` click '' , reset , false ) ; function reset ( ) { alert ( `` reset was clicked '' ) ; }
How to respond to a click outside a certain area ?
JS
When I only perform the next steps in my algorithm if various conditions are met I express it this way : When I only perform the next steps based on the fulfillment of a promise I can express it like this : How can I express in idiomatic JavaScript when condition sc1 is a just a regular old synchronous expression but c...
if ( sc1 || sc2 ) { do ( ) ; various ( ) ; things ( ) ; } asyncCheck ( ) .then ( ac1 = > { if ( ac1 ) { do ( ) ; various ( ) ; things ( ) ; } } if ( sc1 ) { do ( ) ; various ( ) ; things ( ) ; } else { asyncCheck ( ) .then ( ac2 = > { if ( ac2 ) { do ( ) ; various ( ) ; things ( ) ; } } }
Are there idiomatic ways to express `` if ( c1 || c2 ) '' in JavaScript when one of the conditions is a promise and the other is not ?
JS
I need to store an object like the one I the example below in localstorage . I need to be able to retrieve this object and edit it , then save it back into localStorage for next time.I tried this but it said 'undefined ' : What can I do to fix it ? Solved
var data = { lastEdit : '' September '' , expires : '' December '' , records : [ { arrives : `` 12:45 '' , departs : `` 12:51 '' } , { arrives : `` 13:03 '' , departs : `` 13:04 '' } ] } ; localStorage.setItem ( `` dataStore1 '' , data ) ; var output = localStorage.getItem ( `` dataStore1 '' ) ;
Why is n't localStorage accepting my object ?
JS
According to my research , the order of keys in a for..in loop should be undefined/unreliable – but , if left undisturbed , should be in insertion order – but it 's not : I fetch this data object from the database , ordered by name : The keys get ordered numerically ( in all of Chrome , Firefox , and Edge ) . Why ? And...
var travel = { ' 2 ' : { name : 'bus ' , price : 10 } , ' 3 ' : { name : 'foot ' , price : 0 } , ' 1 ' : { name : 'taxi ' , price : 100 } } for ( way in travel ) console.log ( travel [ way ] .name ) // = > taxi , bus , foot
Iteration order of for.in & ndash ; not by insertion ( any more ? )
JS
i do n't know why this program is not working on my computer while other PC doesso when i want to running this program it gives one error is given below , so try to hep for fix it ... index.js posts.jsprofile.jsbut it shows the error something like this in the microsogt edge ... it shows error in mozilla firefox like t...
import React , { Component } from 'react ' ; import ReactDOM from 'react-dom ' ; import { BrowserRouter , Route } from 'react-router-dom ' ; import PropTypes from 'prop-types ' ; import Posts from './components/posts ' ; import Profile from './components/profile ' ; class App extends Component { render ( ) { return < d...
reacter router dom is not working
JS
See belowWhy does Closure raise an error only when using call and not apply ? Is there a way I can made closure type-check the parameters even when I 'm using apply ?
/** * @ param { string } a * @ param { string } b */var f = function ( a , b ) { // ... } /** * @ param { string } a * @ param { boolean } c */var h = function ( a , c ) { f.apply ( this , arguments ) ; // no compile error f.apply ( this , [ a , c ] ) ; // no compile error f.call ( this , a , c ) ; // compile error : d...
Why does not Closure type-check the parameters when using function.apply ?
JS
In JavaScript , 0 % 100 is 0 , but in Elm , the result of the same operation is this.I have just thought remainderBy function better returns Maybe Int like below.Does Elm have any reason why remainderBy returns NaN ?
> remainderBy 0 100NaN : Int > remainderBy 0 100Nothing : Maybe Int > remainderBy 6 3Just 2 : Maybe Int
Why does `` remainderBy 0 100 '' in Elm 0.19 return NaN , not Maybe Int ?
JS
I have good understanding how javascript as well as jQuery can be used in the HTML file but logically one question is arisen.When we want to embed javascript into HTML file , generally ( not every time ) we write this simple code in head part.And when we want to embed jQuery at that time the same peace of codeHow can w...
< script type= '' text/javascript '' > ... < /script > < script type= '' text/javascript '' > ... < /script >
Logic Behind the Use of jQuery ?
JS
I wonder the title is right or not , anyway what I wonder is how can do thing like thisHow can I get the results above ? ? I 've been trying for two days to find the answer in the book and on the internet , but I could n't find it.please help ... . Thanks in advance .
const items = [ a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 .. and so on ] const flexbox1 = [ ] ; const flexbox2 = [ ] ; const flexbox3 = [ ] ; const flexbox4 = [ ] ; for ( const item in items ) { // what I wonder is this part . } == > result : const flexbox1 = [ a1 , a5 , a9 , a13 .. and so on ] ; const flexbox2 = [ a2...
how to put items in an array sequentially ? ( javascript )
JS
I 'm updating mootools from 1.3.2 to 1.4.1.I saw a strange change . From thisto thishow the `` > > > '' operator , used in that way , can improve performance ? What do you think about it ?
for ( var i = 0 , l = this.length ; i < l ; i++ ) { ... . for ( var i = 0 , l = this.length > > > 0 ; i < l ; i++ ) {
For loop improved with `` > > > '' operator ?
JS
I have got a page in my frontend with different buttons , all buttons , on their own , work perfectly , but if I click the button that opens an extension in the chrome web store and click on another button afterwards , the page does n't open.Here is an exmaple of what I am talking about . If you click the buttons witho...
< button id= '' button1 '' onclick= '' window.open ( 'https : //www.facebook.com/ ' , 'popup ' , 'width=700 , height=300 ' ) ; '' > < strong > CONTINUAR < /strong > < /button > < br > < button id= '' button2 '' onclick= '' window.open ( 'https : //www.google.com/ ' , 'popup ' , 'width=700 , height=300 ' ) ; '' > < stro...
Why ca n't I open a tab with a html-button while being on the chrome web store ?
JS
I am a newbie to JavaScript , but I am familiar with Python . I am trying to figure out the differences between the Dictionary in Python and the Object in JS.As far as I know , the key in a dictionary in Python needs to be defined in advance , but it could be undefined in an object in JS . However , I am confused about...
var n = 'name ' ; var n2 = n ; var person = { n : 'mike ' } ; person.n # 'mike'person [ ' n ' ] # 'mike'person [ n2 ] # undefinedperson.n2 # undefinedperson [ 'name ' ] # undefinedperson . 'name ' # undefined n = 'name'n2 = nperson = { n : 'mike ' } person [ n ] # 'mike'person [ n2 ] # 'mike'person [ 'name ' ] # 'mike ...
I am so confused about Object in JavaScript
JS
I have this structure of text : I need to create JS objects : That 's not a problem.The problem is that I want to extract values via Regex split via positive lookahead : Split via the first time you see that next character is a letterWhat have i tried : This is working fine : But If I have 2 words or more : The result ...
1.6.1 Members ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 121.6.2 Accessibility ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . 131.6.3 Type parameters ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 131.6.4 The T generic...
split line via regex in javascript ?
JS
I 've read various `` there is no truly private data in Python instances '' posts , but we 're all aware of using closures in Perl and JavaScript to effectively achieve private data . So why not in Python ? For example : Now we do : What can you do to the instance thing to get read access to the original string ( ignor...
import codecsclass Secret : def __private ( ) : secret_data = None def __init__ ( self , string ) : nonlocal secret_data if secret_data is None : secret_data = string def getSecret ( self ) : return codecs.encode ( secret_data , 'rot_13 ' ) return __init__ , getSecret __init__ , getSecret = __private ( ) > > > thing = ...
Python private instance data revisited
JS
Prepending that a solution only needs to work in the latest versions of Chrome , Firefox , and Safari as a bonus.-I am trying to use an associative array for a large data set with knockout . My first try made it a true associative array : but knockout was not happy with looping over that . So I tried a cheating way , h...
[ 1 : { Object } , 3 : { Object } , ... , n : { Object } ] [ undefined , { Object } , undefined , { Object } , ... , { Object } ] $ .each ( data , function ( index , item ) { self.myArray.splice ( item.PKID , 0 , new Object ( item ) ) ; } < ! -- ko foreach : { data : myArray ( ) , afterRender : setInitialTileColor } --...
Is there a way to map a value in an object to the index of an array in javascript ?
JS
I am responding to mouseenter events on an SVG path element by making the path the last child in its parent . This is so it appears on top of other elements ( no z-index on SVG stuff unfortunately ) . The problem is that on Firefox this causes a mouseleave event to fire . This works fine on Chrome.Does anyone know a wo...
// on mousenternode.parentNode.appendChild ( node ) // this triggers a mouseleave .. if i do n't move the node it works
How to stop Firefox firing mouseleave when DOM node is moved in the DOM ?
JS
Preface : I have a demo of the problem on my personal site ( I hope this is ok . If not , I can try to set it up on jsfiddle ) . I 'm intending this question to be a little fun , while also trying to understand the time functions take in javascript.I 'm incrementing the value of progress bars on a timeout . Ideally ( i...
function setProgress ( bar , myPer ) { bar.progressbar ( { value : myPer } ) .children ( '.ui-progressbar-value ' ) .html ( myPer.toPrecision ( 3 ) + ' % ' ) .attr ( 'align ' , 'center ' ) ; myPer++ ; if ( myPer == 100 ) { myPer = 0 ; } } function moveProgress ( bar , myPer , inc , delay ) { setProgress ( bar , myPer )...
How can I make my setTimout functions run at the same speed ?
JS
On some JS code on some sites I see Javascript code such as this : I mean , this is not a jQuery plugin code such as this : Then , what is it ? and what is the resulting JS object ?
SomeName.init = ( function ( ) { // some stuff } ) ( ) ; ( function ( $ ) { $ .fn.myPlugin = function ( ) { // Do your awesome plugin stuff here } ; } ) ( jQuery ) ;
What is this code in Javascript ?
JS
I have an issue where I have a div class= '' tasteTheRainbow '' and inside are img tags . One tag in particular is a png class named .gA3.Now tasteTheRainbow already has a css background url but when you tap or click the .gA3 I want the background url to change.I have tried many other stackoverflow posts and found no s...
< div class= '' tasteTheRainbow '' > < div class= '' greenArrow '' > < img class= '' gA1 '' src= '' assets/arrows/down.png '' / > < img class= '' gA2 '' src= '' assets/arrows/in.png '' / > < img class= '' gA3 '' src= '' assets/arrows/left.png '' / > < img class= '' gA4 '' src= '' assets/arrows/out.png '' / > < img clas...
css and/or javascript change background on clicking image
JS
So my character div changes its background image when the player presses x which then kills the enemy if the character is touching the enemy . This image switch is to do a mock animation of swinging a sword.I used set timeout to delay switching the background image back to its original state . This works.HOWEVER theirs...
function pressOn ( e ) { e.preventDefault ( ) ; let tempKey = ( e.key == `` `` ) ? `` space '' : e.key ; keys [ tempKey ] = true ; if ( keys [ ' x ' ] & & player.swing == false ) { player.plane.style.backgroundImage ='url ( guts2.png ) ' ; setTimeout ( function ( ) { player.swing = true ; } , 300 ) ; } } function playG...
spam asynchronous callbacks breaking my setTimeout delay
JS
I developed a website for my graduation however it still only one thing I have do . What I want is when the script is installed on a website I want to send the name of the website who has installed my script , also whenever there is an error I want to send it to my website so for example : This website installed my scr...
www.security-dz.com/myscript www.getlog.com/mylogs.php
Send log errors to a file
JS
If metacharacter ? matches the preceding element zero or one time , thenwhyreturns [ `` a '' ] , butreturns [ `` '' ] ?
`` ab '' .match ( /a ? / ) `` ab '' .match ( /b ? / )
why only first letter is returned by match function ?
JS
Consider the below code , I am trying to understand the behaviour between asyncFunction1 and asyncFunction2 execution , the asyncFunction1 takes 2 seconds for each await ( total 6 ) when not assigned to a variable , but asyncFunction2resolves all the 3 promises in total 2 seconds when assigned to a variable , what happ...
// Function which returns a promise and resolves in 2 secondsconst promiseFunction = ( ) = > { return new Promise ( ( resolve , reject ) = > { setTimeout ( ( ) = > { resolve ( 'resolved ' ) ; } , 2000 ) ; } ) ; } ; // Asynchronous function 1const asyncFunction1 = async ( ) = > { console.log ( await promiseFunction ( ) ...
Awaiting promises which is assigned to a variable
JS
If in Chrome console I run proper JSON : I get : If however I run e.g . : It dose n't complain . Also running below is fine : I thought that proper JSON must have properties names wrapped in quotation marks so why is this happening ? Is JS object notation not proper JSON ?
{ `` aaa '' : '' bbb '' } SyntaxError : Unexpected token : { aaa : '' bbb '' } aaa= { `` aaa '' : '' bbb '' }
Is JavaScript Object notation proper JSON ?
JS
I 'm trying to store a directory tree in a mongoDB . Here 's my schema : I want to changes this so that the children get nested inside the parents . i.e . : Here 's the function I 'm using to try to accomplish this : I call the function like this : My console returns this : Why is children undefined ? Here 's a live de...
{ `` _id '' : ObjectId ( `` 541ba7f156d876d3f787bc33 '' ) , `` name '' : `` file_1.mp3 '' , `` length '' : 136.6 , `` kind '' : `` audio '' , `` parent '' : null } { `` _id '' : ObjectId ( `` 541ba7f156d876d3f787bc34 '' ) , `` name '' : `` file_2.mp3 '' , `` length '' : 132.0 , `` kind '' : `` audio '' , `` parent '' :...
Build javascript tree based on parent attribute in array of elements
JS
I have added a form in my app . When I send the form data to my local server I create an image with a title . When I attach images I should be using input type= '' file '' . Also , I should use FormData in my app.But when I write my component I have an error 'formElem ' is not defined in the two lines commented in the ...
const AddImage = ( props ) = > { formElem.onsubmit = async ( e ) = > { // ERROR THERE e.preventDefault ( ) ; try { const response = await api ( ` $ { imageRoute } ` , { method : 'POST ' , body : new FormData ( formElem ) , // ERROR THERE } ) ; } catch ( e ) { console.error ( e ) ; } } ; return ( < div className= '' for...
How to correctly write FormData in my React app ?
JS
I have a task model which is related to the user and project models.When I create/update a task , I need to do an update in the view async , not only for the task change/addition , but to the project and user info ( because some of that data might change too ) .I have this in the controller : And my tasks/create.js.cof...
def create @ task = Task.new ( params [ : task ] ) @ project = Project.find ( params [ : project_id ] ) respond_to do |format| if @ task.save format.html { redirect_to @ task , notice : 'Task was successfully created . ' } format.json { render json : @ task , status : : created , location : @ task } else format.html { ...
Pattern to render multiple coffee
JS
I am using JQuery , and I would like to know if the remove ( ) method cleans its contents of event handlers . For instance : At this point is there an event handler still hanging out in memory ? If so , is there a way to clear the element object of event handlers before removing it from the DOM ?
function someFunction ( ) { var element = $ ( ' < div > < /div > ' ) ; element.click ( function ( ) { alert ( 'bar ' ) ; } ) ; $ ( 'body ' ) .append ( element ) ; element.remove ( ) ; }
Is it necessary to unbind events from elements removed from a document
JS
I have the following javascript that adds a new row to the bottom of a table.It works fine in Firefox , but it does n't work in IE ( version 8 ) .There are no visible errors , as far as I can tell . Any ideas are very helpful !
function addRow ( ) { // locate the last row in the table var table = document.getElementById ( `` approversTable '' ) ; var rows = document.getElementsByTagName ( `` tr '' ) ; var rowToClone ; for ( var i=0 ; i < rows.length ; i++ ) { if ( rows [ i ] .id ! = `` '' ) { rowToClone = rows [ i ] ; } } // clone the row var...
why does n't this 'addRow ' javascript work in IE ?
JS
I am trying to write javascript code to find all the urls inside a div . Now this would be pretty easy if all the urls within the div were separated by spaces in which case I can just do a regex on what 's inside the div to find them . However , the urls within this outer div may be in sub divs ( or any other html tag ...
< div id= '' outer '' > < div > www.foo.com < /div > www.bar.com < /div >
Replacing all urls in a div
JS
I am able to filter the elements of matrix W to elements that satisfy the conditional statement = > keep elements in each inner matrix that is below the median value . The elements of the median array are the median values for each inner array . I used a for-loop , but the resulting Wmin array is flattened . My goal is...
const W = [ [ 45 , 60 , 15 , 35 ] , [ 45 , 55 , 75 ] , [ 12 , 34 , 80 , 65 , 90 ] ] ; const median = [ 40 , 55 , 65 ] ; const Wmin = [ ] ; for ( let j = 0 ; j < W.length ; j++ ) { for ( let k = 0 ; k < W [ j ] .length ; k++ ) { if ( W [ j ] [ k ] < median [ j ] ) { Wmin.push ( W [ j ] [ k ] ) ; } } } console.log ( Wmin...
Get unflattened filtered Multidimensional Array in Javascript
JS
In my spelling game at the moment , the grid is designed for 3 letter words . I can add bigger words into the `` wordList '' ( which creates the grid dynamically ) , but the size of the grid changes and overlaps on the rows where the bigger words are.At the moment when a four letter word is added for example , the grid...
< ul style= '' display : none ; '' id= '' wordlist '' > < li data-word= '' rat '' data-audio= '' http : //www.wav-sounds.com/cartoon/bugsbunny1.wav '' data-pic= '' http : //www.clker.com/cliparts/C/j/X/e/k/D/mouse-md.png '' > < /li > < /ul > var listOfWords = [ ] ; var rndWord = [ ] ; var counter = 0 ; var ul = documen...
Stopping overlap for bigger words
JS
I use jQuery to intentionally remove css classes from elements in a potentially large html table . See below for an explanation why I am doing that.Currently I am doing it like this : The table sometimes is large and has many elements . I would like to speed up the page load / DOM manipulation.The IE 's built-in Javasc...
var tableElements = $ ( `` # TreeListElemente '' ) .find ( `` * '' ) .addBack ( ) ; tableElements.removeClass ( `` dxtl dxtl__B2 dxtl__B0 dxtlSelectionCell dxtlHeader dxtl__B3 dxtlControl dx-wrap dxtl__IM dxeHyperlink '' ) ; $ ( `` # TreeListElemente , # TreeListElemente [ class ] '' ) .removeClass ( `` dxtl dxtl__B2 d...
Optimizing jQuery selector / addBack ( ) when dealing with a large collection
JS
I 've got some very odd behaviour going on . I have the following JQuery : There is some kind of race condition going on , such that the element does n't end up getting hidden . If I put a debugger on that line and step through the code , it works fine and the element fades out and gets hidden . Call it a Heisenbug.My ...
myElement.fadeOut ( 100 ) ;
Does the JS debugger suspend the whole JS event loop ?
JS
So , I 'm trying to save and load a cookie that contains a list of product details and then display these product details to the page . However when I run this what I receive is a ReferenceError : Ca n't find variable : GetProductPrice when trying to read the cookies I stored using the GetProductPrice ( ) function . Th...
function setUpProducts ( ) { //in here we define each of the products when we first start up . This way we know what products the customer has access to . setUpPages ( ) ; try { hasRun = getCookie ( 'hasRunCookie ' ) ; //get the has run cookie from before , or at least try to } catch { hasRun = 0 ; } //if ( hasRun ! = ...
Issue with storing and recalling cookies Javascript
JS
I 'm fairly new to Javascript ( just finished the book Eloquent Javascript ) , and am currently reading AngularJS from O'Reilly . And getting this small snippet of code to work from the book drove me crazy for hours and led me down rabbit holes thinking I messed up somewhere in setting up my environment.The only differ...
< ! doctype html > < html ng-app > < body ng-controller= '' TextController '' > < p > { { someText } } < /p > < script src= '' angular.min.js '' > < /script > < script > function TextController ( $ scope ) { $ scope.someText = 'You have started your journey . ' ; } < /script > < /body > < /html >
Why is the variable name `` $ scope '' necessary ?
JS
I really want to get this working with no jQuery if possible . I 'm trying to make the SVG path called `` mouth '' be animated through the slider with JavaScript , so the path will seamlessly move to appear sad or happy .
< ! DOCTYPE HTML > < html > < head > < meta charset= '' UTF-8 '' > < meta name= '' description '' content= '' Pattern editor '' > < meta name= '' keywords '' content= '' HTML , CSS , SVG , JavaScript '' > < script > < ! [ CDATA [ function refresh ( ) { var slider1 = parseInt ( document.getElementById ( `` slider1 '' ) ...
JavaScript , SVG , HTML , and CSS
JS
I have an example of my current work here : https : //jsfiddle.net/pv5xroLc/My problem is that when the table in my example is fully scrolled to the right , the faded gradient still covers part of my table even though it can not be scrolled further , thus it makes the last column harder to read . I am wondering what th...
< div class= '' fader '' > < div class= '' scrollable '' > *content* < /div > < /div >
Best approach to hide an absolutely positioned < div > when horizontally scrolling ?
JS
I am currently stuck with a small issue here . I have used a mark-up like this : SnippetProblemI am trying to design a User Profile Bar , which when live , it should be this way : This is what I am trying to achieve here , when the button is clicked . And also what happens is , the menu does n't get displayed , because...
$ ( function ( ) { $ ( `` .more-options '' ) .click ( function ( ) { $ ( this ) .closest ( `` .user-profile '' ) .toggleClass ( `` open '' ) ; return false ; } ) ; } ) ; /* Reset */* { margin : 0 ; padding : 0 ; list-style : none ; font-size : 12pt ; } a { text-decoration : none ; } /* Main CSS */.user-profile { border...
Better approach for User Profile bar
JS
I am developing a Chrome extension and my requirement is to create element ( button ) on page for each tab open and wants to show simple alert message on clicking button..it works properly for all but it always creating issue with Gmail , Facebook and Stackoverflow..please help me to resolve this issue.I am having the ...
manifest.json ... . ... . `` content_scripts '' : [ { `` matches '' : [ `` http : //*/* '' , `` https : //*/* '' ] , `` css '' : [ `` style.css '' ] , `` js '' : [ `` contentScript.js '' ] , `` all_frames '' : false , `` run_at '' : `` document_idle '' } ] ... . ... . ... ... .. function addButton ( ) { document.body.i...
Element created by Content script on page creating issue with Gmail , Facebook , stackoverflow etc
JS
I 'm wondering if these two blocks of code are the same in Node.js ? Since above I 'm passing 0 for the timeout , there should be no waiting time . Is it identical to just calling console.log ( 'hello ' ) ; directly without using setTimeout ?
// Style 1setTimeout ( function ( ) { console.log ( 'hello ' ) ; } , 0 ) ; // Style 2console.log ( 'hello ' ) ;
Javascript are these calls the same in Node.js ?
JS
I am using the code showed below to create 46 small circles within a wrapper ( div ) draw-shapes ; All drawings are made with the Two.js library . I read in the documentation I can change the id of the created element , but I also need to assign a class to each element . I have tried everything from pure js setAttribut...
let elem = document.getElementById ( 'draw-shapes ' ) ; let params = { width : 1024 , height : 768 } ; let two = new Two ( params ) .appendTo ( elem ) ; for ( let i = 1 ; i < 47 ; i++ ) { circle = two.makeCircle ( x , y , radius ) ; circle.fill = 'green ' ; circle.stroke = 'white ' ; circle.linewidth = 1 ; circle.id = ...
Can I add class to dynamically created two.js element ?
JS
I 'm writing a little cached function in a plugin / library . It takes a HTMLElement and returns a Decorator.Here I 'm storing some expensive operation in a cache by the id of the HTMLElement . This is a O ( 1 ) lookup but it uses the `` bad practice '' of setting elem.id and having a side effect.The alternative would ...
return function _cache ( elem ) { if ( elem.id === `` '' ) { elem.id = PLUGIN_NAME + `` _ '' + uid++ ; } if ( cache [ elem.id ] === void 0 ) { cache [ elem.id ] = _factory ( elem ) ; } return cache [ elem.id ] ; } return function _cache ( elem ) { for ( var i = 0 , ii = cache.length ; i++ ) { var o = cache [ i ] ; if (...
Is setting element.id as a side effect bad practice ?
JS
Here My requirement is once we select the SON or Father in one select box and if I select 'Mother-In-law ' or 'Father-In_law ' in another select boxes , I want one alert message like 'In-laws are not applicable'.Here is my code , Can any one help me please . The jsFiddle is here.-Thanks .
if ( arr.indexOf ( ! ( ( $ ( this ) .val ( ) == 'Son ' || $ ( this ) .val ( ) == 'Father ' ) ) ) > -1 ) { alert ( 'In-laws are not applicable ' ) ; return false ; }
Validation for dropdown boxes selection ?
JS
I stumbled upon the following ES6 method during a rewiew : This seems buggy to me . I would have expected the following : But then , I know that async has many tricks such as auto-wrapping promises , so is my intuition correct ?
async getUsers ( res ) { User.findAll ( ) .then ( users = > res.json ( users ) ) ; } async getUsers ( res ) { return User.findAll ( ) .then ( users = > res.json ( users ) ) ; }
What is the correct syntax for a method declared as async ?
JS
Maybe this question is easy , but I ca n't understand now.If you know the reason , please tell me why the result is `` false '' .
String.prototype.self=function ( ) { return this ; } var s= '' s '' ; alert ( `` s '' .self ( ) == '' s '' .self ( ) ) //false ; alert ( s.self ( ) ==s.self ( ) ) //false ;
The inheritance of javascript
JS
I 've been reading a few articles , and have n't found the example that solves my issue.My understanding is that : ng-if and ng-repeat create isolate scopes.Using $ parent.someProperty is bad.Using $ parent. $ parent.someProperty would be an abomination.So , with the given template markup , how can I properly bind the ...
< div ng-app= '' MyApp '' ng-controller= '' MyCtrl '' > < div ng-if= '' showOnCondition '' > < label ng-repeat= '' item in repeatingItems '' > { { item } } < setting item= '' item '' / > < /label > < /div > { { checkSetting ( ) } } < /div > var myApp = angular.module ( 'MyApp ' , [ ] ) ; myApp.controller ( 'MyCtrl ' , ...
Proper method to handle Angular scope instead of $ parent. $ parent
JS
How can I get this effect below to happen inside the modal ? I have tried a bunch of methods and it seems like I am missing something . When I put all of the content in the .wrap div inside the `` MODAL CONTENT '' div it no longer shows anywhere . Then when I correct the css to target the modal properly # myModal modal...
var lFollowX = 0 , lFollowY = 0 , x = 0 , y = 0 , friction = 1 / 30 ; function moveBackground ( ) { x += ( lFollowX - x ) * friction ; y += ( lFollowY - y ) * friction ; translate = 'translate ( ' + x + 'px , ' + y + 'px ) scale ( 1.1 ) ' ; $ ( '.bg ' ) .css ( { '-webit-transform ' : translate , '-moz-transform ' : tra...
How to make JS/Jquery perspective effect work inside modal ?
JS
I 'm new to JavaScript and I wonder why it 's not working for me : I also tried to save $ ( this ) as a variable when clicking the .class , but that did n't work for me also .
function resetColor ( ) { $ ( this ) .css ( { `` color '' : `` red '' } ) } $ ( '.class ' ) .click ( function ( ) { resetColor ( ) ; } ) ;
Use $ ( this ) in an outside function
JS
In my state I have showTab1 , showTab2 , showTab3 . If tab i is selected , then the other tabs are set to false . So in my render function I want to be able to return something like this : But I know that it 's not allowed to have multiple returns , or at least it 's considered bad practice . How can I get around this ...
return ( < div > { ( ( ) = > { if ( someCondition ) { if ( this.state.showTab1 ) { return ( < div > < Tab1/ > < /div > ) } else if ( this.state.showTab2 ) { return ( < div > < Tab2/ > < /div > ) } else if ( this.state.showTab3 ) { return ( < div > < Tab3/ > < /div > ) } } return < span / > ; } ) ( ) } < AnotherComponen...
React - How to return one of several components in the render function ?
JS
We have a html div ( first image ) and array of strings ( see second image ) We have to assign the single index like safety [ A4 ] and safety [ A5 ] to the text of div.But currently it assign two footnote to same text like safety [ A5 ] [ A4 ] since safety occurs two times in the html div.Our current attempt is : How c...
for ( var i = 0 ; i < totalNumberOfItemsInCorrelationGrid ; i++ ) { var currentDataItem = data [ i ] ; arr = new Array ( currentDataItem.correlation_text , currentDataItem.corr ) ; arrOfCorrelatedTextOfCorrelationGrid.push ( arr ) ; } // sorting from bigger length of string to smaller length of stringarrOfCorrelatedTex...
assigning index to text of div jquery
JS
I have some PHP and front-end JavaScript experience , but am trying to make a Node.js REST API to serve the Vue.js client-side of one of my applications , however I am struggling to get around a certain concept . So far I have primarily been following documentation and guides online.I am using Express.js and a MySQL da...
// constructorconst Customer = function ( customer ) { this.email = customer.email ; this.name = customer.name ; this.active = customer.active ; this.created_at = customer.created_at } ; Customer.getAll = result = > { sql.query ( `` SELECT * FROM customers '' , ( err , res ) = > { if ( err ) { console.log ( `` error : ...
How to handle non traditional queries in Node.js REST APIs
JS
I have a page where I 've tried to put a JQuery dialog where data is entered and later goes to a server . The problem I 've encountered is that the dialog is outside the form tag , since that whole data I enter is lost somewhere . It looks like this : I 've tried this so far : But it only appends dialogAddPart , not it...
var dialogAddPartDiv = $ ( '.dialogAddPart ' ) ; $ ( 'form ' ) .append ( dialogAddPartDiv ) ;
How do I put a dialog div in form tag
JS
According to JavaScript - The Definitive guide , JavaScript assumes that the source code it is interpreting has already been normalized and makes no attempt to normalize identifiers , strings , or regular expressions itself.The Unicode standard defines the preferred encoding for all characters and specifies a normaliza...
`` café '' === `` caf\u00e9 '' // = > true `` café '' === `` cafe\u0301 '' // = > false
Who performs unicode normalization and when ?
JS
Here is my code : The result should be just three and two in console . Because just they contain t letter . But as you see all values will be shown in the console.As I 've mentioned , I 'm trying to make a small search engine for a autocomplete box . How can I fix it ?
if ( $ ( 'span ' ) .text ( ) .indexOf ( `` t '' ) ) { console.log ( $ ( 'span ' ) .text ( ) ) ; } < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < span > one < /span > < span > two < /span > < span > three < /span > < span > four < /span > < span > five < /span > < ...
How to search at element 's value ?
JS
Possible Duplicate : What does this mean ? ( function ( x , y ) ) { … } ) { a , b ) ; in JavaScript I am a starter to javascript . I know to write JS userdefined functions . But recently I came across some thing that I can ’ t recognize . Can anyone explain to me what this is ? What is the meaning of this ? When I Goog...
( function ( window , undefined ) { var jQuery = ( function ( ) { } ) ; window.jQuery = window. $ = jQuery ; } ) ( window ) ; function foo ( ) { alert ( `` This is an alert '' ) ; }
why are javascript functions like this
JS
Let 's say I have 7 small bins , each bin has the following number of marbles in it : I assign these small bins to 2 large bins , each with the following maximum capacity : I want to find EVERY combination of how the small bins can be distributed across the big bins without exceeding capacity ( eg put small bins # 4 , ...
var smallBins = [ 1 , 5 , 10 , 20 , 30 , 4 , 10 ] ; var largeBins = [ 40 , 50 ] ; //Brute forcevar smallBins = [ 1 , 5 , 10 , 20 , 30 , 4 , 10 ] ; var largeBins = [ 40 , 50 ] ; function getLegitCombos ( smallBins , largeBins ) { var legitCombos = [ ] ; var assignmentArr = new Uint32Array ( smallBins.length ) ; var i = ...
Efficiently find every combination of assigning smaller bins to larger bins
JS
Executing this recursive fibonacci function takes around 9.5 seconds on my machine , using a traditional approach : However , when I wrap the body of the function in another function that gets executed right away , execution drops to 7.5 seconds : This is a huge speedup ( ~30 % ! ) , but I can not figure out why wrappi...
const fib = n = > { if ( n == 1 ) return 0 ; if ( n == 2 ) return 1 ; return fib ( n - 1 ) + fib ( n - 2 ) ; } ; console.log ( fib ( 45 ) ) ; ➜ time node index.js701408733node index.js 9,50s user 0,04s system 99 % cpu 9,566 total const fib = n = > { return ( ( ) = > { if ( n == 1 ) return 0 ; if ( n == 2 ) return 1 ; r...
Why is this wrapped function call faster than a regular function ?
JS
I 'm trying to select only certain values from my object to write into a file . But this writes the whole object and also unless I use util.inspect it just writes as objects . This should write the values I have chosen from the objects line by line as they come in : objectsTotal comes through the function like : The ou...
var objectsToFile = function ( objectsTotal ) { objectsTotal = _.values ( objectsTotal , function ( value ) { return value.objectTo.employeeName ; } ) ; objectsTotal = _.values ( objectsTotal , function ( value ) { return value.employeeCurrent ; } ) ; objectsTotal = _.values ( objectsTotal , function ( value ) { return...
Node WriteFile not writing objects I need using underscore . Writes the whole objects
JS
I have an anchor link with no destination , but it does have an onClick event : I understand that I can not directly execure PHP code blocks in JavaScript due to the nature of PHP and it being a server side language , so I have to utilize AJAX to do so . When the delete link is clicked , I need it to execute this query...
< li > < a href onClick='deletePost ( ) ' > Delete < /a > < /li > < ? php include ( `` connect.php '' ) ; $ delete_query = mysqli_query ( $ connect , `` DELETE FROM user_thoughts WHERE id = 'id ' `` ) ; ? > function deletePost ( ) { xmlhttp=new XMLHttpRequest ( ) ; xmlhttp.onreadystatechange = function ( ) { if ( xmlht...
Using AJAX to execute a PHP script through a JavaScript function
JS
I have a certain custom validation directive in my application ( code attached below ) .The problem is that when one or more of the form fields are required , and chrome fills them automatically , the fields remain invalid until the user changes them manually.I suspect that this happens due to the fact that chrome fill...
app.directive ( 'myValidate ' , function ( $ timeout , $ filter ) { return { require : 'ngModel ' , link : function ( scope , elm , attrs , ctrl ) { var validator = function ( viewValue ) { var viewValueStr = viewValue + `` ; scope.valid = true ; scope.fieldName = attrs.name ; var nameStr = attrs.name + `` ; if ( ! att...
$ parsers \ $ formatters functions are not firing when the browser fills the form field automatically
JS
I built a component that is basically a rating system that allows you to add more icons depending on the dropdown . I was wondering if there was a way to make half stars , I 've looked through older code on the internet , but there is n't anything that has been updated . Any help with be appreciated
import React , { useState } from 'react'import { FaStar } from `` react-icons/all '' ; import './Rater.css'const Rater = ( ) = > { const [ rating , setRating ] = useState ( null ) const [ hover , setHover ] = useState ( null ) const [ value ] = useState ( 100 ) const [ iconValue , setIconValue ] = useState ( 5 ) return...
Setting up half-icons with a rating system
JS
I want to catch numbers appearing anywhere in a string , and replace them with `` ( .+ ) '' .But I want to catch only those numbers which have an even number of % s preceding them . No worries if any surrounding chars get caught up : we can use capture groups to filter out the numbers.I 'm unable to come up with an ECM...
abcd % 1 % % 2 % % % 3 % % % % 4 efghabcd % 12 % % 34 % % % 666 % % % % 11efgh
How to match only those numbers which have an even number of ` % ` s preceding them ?
JS
My expectation from the following code would be that if I checked a.name , it would search the prototype and return it as it was declared . Can anyone pinpoint what it is that is preventing JS from acknowledging my prototype ?
var obj = function ( parent ) { return { prototype : parent } } ; var me = { name : 'keith ' } ; var a = new obj ( me ) // = > undefineda.name// = > undefineda.prototype.name// = > `` keith ''
Javascript Prototype Quirk - Can Anyone Explain This ?
JS
Suppose you want to launch a ( random ) process for every folder in a list in a short code : If the list is long , i might end up running a large amount of processes concurrently , which is to be avoid . What 's a fairly simple way to run the executions on a controlled rate ( maximum 5 concurrent process here ) ? edit ...
var exec = require ( 'child_process ' ) .exec ; var folders = [ ... ] ; // a list from somewhere_.each ( folders , function ( folder ) { exec ( `` tar cvf `` + folder + `` .tgz `` + folder ) ; } ) ;
Control the rate of a javascript asynchronous flow ( in a loop )
JS
The console shows undefined , rather than 'testing ' . What am I doing wrong ?
function a ( ) { this.testing = 'testing ' ; } function b ( ) { } b.prototype = new a ( ) ; console.log ( b.testing ) ;
Prototypal Inheritance . Whats wrong with this simple example ?
JS
I have a textarea like this : Now I need to get the biggest number which is in [ ] . In this case I need to get 3 . How can I do that ?
< textarea > this is a test [ 1 ] also this [ 2 ] is a testand again [ 3 ] this is a test < /textarea >
How to get biggest number in textarea ?
JS
As someone who is attempting to take a more object oriented approach to my javascript programming I 've hit a stumbling block which I 'm sure is probably something very basic , but , take the following object implementation ( assume that the jQuery object is available to this code ) :
function Foo ( ) { this.someProperty = 5 ; } Foo.prototype.myFunc = function ( ) { //do stuff ... } ; Foo.prototype.bar = function ( ) { //here 'this ' refers to the object Foo console.log ( this.someProperty ) ; $ ( '.some_elements ' ) .each ( function ( ) { //but here , 'this ' refers to the current DOM element of th...
JavaScript Scope question
JS
I have two sets of data in a JSON ( data.json ) as below : And I have an HTML form which the user will use to login . On the click of the submit button I want to first check if the username ( stored in a var , say x ) entered belongs to the Admins list in my JSON file or not . Eg : if x is jhon I want to know if the sa...
UP = [ { `` password '' : `` jhonjhon '' , `` username '' : '' jhon '' } , { `` password '' : `` juliejulie '' , `` username '' : '' julie '' } , { `` password '' : `` blakeblake '' , `` username '' : '' blake '' } ] ; Admins = ' [ { `` Admin '' : '' jhon '' } , { `` Admin '' : '' julie '' } ] ' ; < html > < body > < f...
How to check for one JSON object being present in another
JS
I have object structure like below I want to convert that object to below formatIf there is one more property after [ ' % ' , '- ' , '+ ' ] in above case , same process continues..Please suggest me to complete this logic .
var obj = { a : 1 , b : [ x , y , z ] , c : [ 0,1,3 ] , d : [ ' % ' , '- ' , '+ ' ] } { 1 : { x : { 0 : [ ' % ' , '- ' , '+ ' ] , // Last index remains as an array 1 : [ ' % ' , '- ' , '+ ' ] , 3 : [ ' % ' , '- ' , '+ ' ] } , y : { 0 : [ ' % ' , '- ' , '+ ' ] , // Last index remains as an array 1 : [ ' % ' , '- ' , '+ ...
How can I implement this logic
JS
I 'm learning javascript . I know we can pass a function to other functions after the function is defined . But I need help on understanding this example : From what I can understand , func is an argument of map . I need to provide a function as func . But in the tutorial I 'm reading , it does n't mention where this f...
function map ( func , array ) { var result = [ ] ; forEach ( array , function ( element ) { result.push ( func ( element ) ) ; } ) ; return result ; } function count ( test , array ) { return reduce ( function ( total , element ) { return total + ( test ( element ) ? 1 : 0 ) ; } , 0 , array ) ; }
javascript : Passing functions
JS
In some Javascript code which uses immediate function , it has argument window or document like the following : However , window and document are global objects and can be directly accessed as follow : What are the differences between the above two codes . Which is better way and why ?
( function ( window , document ) { ... } ) ( window , document ) ; ( function ( ) { var userAgent = window.navigator.userAgent ; ... var el = document.getElementById ( ... ) ... } ) ( ) ;
What are the differences between following two javascript code ?
JS
I 'm trying to apply prototyped inheritance to a function in Javascript . It 's all pretty plain and even described in Wikipedia 's javascript lemma . It works if my properties are simple javascript types : With Employee.prototype = new Person ( ) ; , all Person 's properties and ( prototyped ) methods are inherited by...
function Person ( ) { this.age = 0 ; this.location = { x : 0 , y : 0 , absolute : false } ; } ; function Employee ( ) { } ; Employee.prototype = new Person ( ) ; Employee.prototype.celebrate = function ( ) { this.age++ ; } var pete = new Employee ( ) ; pete.age = 5 ; pete.celebrate ( ) ; var bob = new Employee ( ) ; bo...
javascript prototyped inheritance and object properties
JS
My code is : The button : I want the button to change to `` Downloading ... '' then return to `` Download as CSV '' a few seconds after , is this possible in JS ?
function changeText ( ) { document.getElementById ( 'button ' ) .innerHTML = 'Downloading ... ' ; } < button id = `` button '' onclick='changeText ( ) ' value='Change Text ' > Download file as CSV < /button >
How to return the previous text after an onclick JS function ?
JS
I need to filter an array and I am totally drawing a blank on how to do so.I need to filter out the largest numbers . A number can be deemed larger when the first number is 'XXXX ' and the second is 'XXXX-1 ' , then the second number is larger . Or it can be deemed larger if the first number is 'XXXX-1 ' and the second...
[ '7851 ' , '7851-2 ' , '7851-1 ' , '2234 ' , '2235 ' , '2235-1 ' ] [ '7851 ' , '7851-1 ' , '2235 ' ]
filtering an array of strings
JS
I want to check if an input element is a checkbox or text type.I know I can do this : But my question is : why do hasOwnProperty returns false ? I just want to use : but it returns false everytime.Is n't input an object ? I do n't think so , but typeof said it is : So what is going on ? ! Code example : The documentati...
//Type of input..if ( input.type === `` checkbox '' ) //Contains the property..if ( `` checked '' in input ) input.hasOwnProperty ( `` checked '' ) typeof input // returns `` object '' const input = document.querySelector ( `` input '' ) if ( input instanceof HTMLInputElement ) { console.dir ( input ) ; console.info ( ...
Why ca n't `` hasOwnProperty '' be used on instanceof HTMLInputElement ?
JS
I have some JavaScript for three HTML divs , mm , ss and pp . These three fields are animated with each other ... If the contents of an external file change , these fields get updated in my page . They get updated with animations.If mm changes , then : ss hides , thenpp hides , thenmm hides , thendivs get updated , the...
if ( $ ( ' # mm ' ) .html ( ) ! = mm ) { hideElem ( '.score ' ) ; setTimeout ( function ( ) { hideElem ( '.player ' ) ; setTimeout ( function ( ) { hideElem ( '.match ' ) ; setTimeout ( function ( ) { updateElems ( ) ; setTimeout ( function ( ) { showElem ( '.match ' ) ; setTimeout ( function ( ) { showElem ( '.player ...
Cleaning up some ridiculous JavaScript code
JS
I have this html code : Is it possible to delete all elements with `` first div '' class if the background image is not : url ( https : //good.jpg ) ; ? so the final response will be : I would be grateful for any assistance , thank you !
< div class= '' first div '' > < div class= '' second '' > < div class= '' title '' > Hi < /div > < div class= '' test-icon '' style= '' background-image : url ( https : //1.jpg ) ; '' > < /div > < /div > < /div > < div class= '' first div '' > < div class= '' second '' > < div class= '' title '' > Hi < /div > < div cl...
jquery/javascript remove div if jpg not match
JS
In my Webapp I need to implement an API , which does not contain any ES6 class definitions , but I would like to extend of one of these classes and override some methods . Overriding does not work properly ... I expect `` B '' as result but the method of `` class '' A gets executed .
function A ( ) { this.msg = function ( ) { console.log ( `` A '' ) ; } } class B { constructor ( ) { A.call ( this ) ; } msg ( ) { console.log ( `` B '' ) ; } } new B ( ) .msg ( ) ;
JavaScript override from a non ES6 class to an ES6 class
JS
Inspired by preact 's `` no build tools route '' , I recently created a project with no build or bundling process . Conceptually , it looks like this ( pseudo code following ) .I have a dependency on react-button which uses e.g . microbundle to resolve the preact import through the node_modules folder.Then , there 's m...
// dependency 1 : `` preact-button '' npm package ( uses bundler ) import { h , Component , render } from 'preact ' ; const button = h ( 'button ' , null , 'Click ' ) ; export default Button ; < ! doctype html > < html > < head > < meta charset= '' utf-8 '' / > < title > SO App < /title > < script type= '' module '' > ...
Is mixing bundled modules and JavaScript Modules possible
JS
I am actually not sure if I just stumbled upon an unwanted behavior in javascript or if this is somehow intended behavior . The following code results in a true statement : http : //jsfiddle.net/xyatxm2g/2/If I change it to the following code , it returns false as it should : http : //jsfiddle.net/fg06ovvc/2/
var test= { `` test '' :1 } document.write ( `` constructor '' in test ) ; var test= { `` test '' :1 } document.write ( test.hasOwnProperty ( `` constructor '' ) ) ;
Odd javascript behavior for checking `` constructor '' key in object
JS
I 'm using jVectorMaps . I have a map object with a backgroundColor property : Let 's say I declare a global bgcolor variable . Then , I change the value of that variable at some point : The idea is that the jVectorMap background color changes when I change the value of the bgcolor variable . So far I was not able to d...
map = new jvm.Map ( { container : $ ( ' # map ' ) , map : `` world_mill_en , backgroundColor : bgcolor function changeBGcolor ( ) { bgcolor = `` yellow '' ; }
Dynamically change object property
JS
Is it possible to alias e.g . the HTMLElement.offsetWidth property , the same way I can alias methods likeI tried : but got : TypeError : 'offsetWidth ' getter called on an object that does not implement interface HTMLElement .
EventTarget.prototype.on = EventTarget.prototype.addEventListener HTMLElement.prototype.w = HTMLElement.prototype.offsetWidth
Aliasing interface property
JS
For example I found some api library that is based on promises , and I need to issue api requests using this library in some interval , infinite times ( like usual back-end loop ) . This api requests - actually chain of promises.So , if I write function like : Will it cause stack overflow ? Solutions that I come up wit...
function r ( ) { return api .call ( api.anotherCall ) .then ( api.anotherCall ) .then ( api.anotherCall ) ... .then ( r ) } function r ( ) { return api .call ( api.anotherCall ) .then ( api.anotherCall ) .then ( api.anotherCall ) .then ( ( ) = > { setTimeout ( r , 0 ) } ) }
Recursive promises can cause stack overflow ?
JS
This is a part of infinite scroll which also works when we scroll upwards : JS code : Js Fiddle : http : //jsfiddle.net/LRLR/ocfLkxex/Issue : Whenever prependTo is called , the data is shifted downwards and new data is added at the top . The scrollbar seems to ignores this , and from the users ' point of view , everyth...
< div id= '' sContainer '' > < div class= '' message0 '' > Initial Content 111 < /div > < div class= '' message1 '' > Initial Content 222 < /div > < div class= '' message2 '' > Initial Content 333 < /div > < div class= '' message3 '' > Initial Content 444 < /div > < div class= '' message4 '' > Initial Content 555 < /di...
When prepending data to vertically-scrolled document , how can I keep previous part visible ?
JS
Why does the first input work correctly , but the second input gives me a result for 5 hours ago ? how can i get the second one to cooperate with me ?
new Date ( `` 2000-1-1 '' ) Sat Jan 01 2000 00:00:00 GMT-0500 ( EST ) new Date ( `` 2000-01-01 '' ) Fri Dec 31 1999 19:00:00 GMT-0500 ( EST ) var a = new Date ( `` 2000-1-1 '' ) ; // Sat Jan 01 2000 00:00:00 GMT-0500 ( EST ) var b = new Date ( `` 2000-01-01 '' ) ; // Fri Dec 31 1999 19:00:00 GMT-0500 ( EST ) console.lo...
Similar Date Format produces unexpected date Javascript
JS
So I 'm just about to add a new function to our every growing list of global ones ( sigh ) and noticed the last user used a variable assignment over simple function a ( ) { } .I created a test to see if it made a difference ; It does , but a conflicting one . ( chrome favours the simple function , while firefox the var...
function aFunction ( ) { return null ; } var bFunction = function ( ) { return null ; }
Why would assigning a function to a var be different than simply defining it ?
JS
I am using Syncano as a baas , where I am trying to call an external API to receive a JSON array . This JSON needs to be parsed and afterwards stored in syncano . Before that I need to receive the reference object from the DB to link it to the new team object.I receive the team ( json ) array & reference object success...
//TODO : get from ARGS when executing this codeboxvar teamKey = 394 ; var requestURL = 'http : //api.football-data.org/v1/soccerseasons/ ' + teamKey + `` /teams '' ; var request = require ( `` request '' ) ; var Syncano = require ( 'syncano ' ) ; var Promise = require ( 'bluebird ' ) ; var account = new Syncano ( { acc...
Syncano Codebox - Call API - parse JSON - get Reference - Save new Objects
JS
Note : I do the javascript code according to the ajrwhite answer . Hope it helps someone . Link : http : //codepen.io/eMineiro/pen/EKrNBe Open codepen console to see the examples working.In poker we define player position according to the dealer . Like this : Blue : Small Blind and Big Blind positionsGreen : Late and D...
players : [ 1,2,3,4,5,6,7,8,9,10 ] ; positions : [ `` bb '' , '' sb '' , '' btn '' , '' late '' , '' medium '' , '' medium '' , '' medium '' , '' early '' , '' early '' , '' early '' ] ; changePosition ( 10 ) ; //means that `` player10 '' now is the new Dealer players : [ 2,1,10,9,8,7,6,5,4,3 ] ; positions : [ `` bb ''...
Determine Poker Table Positions - Sit ' n Go Tournaments
JS
Is there an easier / shorter way with Jquery for writing an if statement like this : The number variable is just an input field where the user enters a number from 0 - 10.Thank you !
if ( number === `` 0 '' ) { degrees = `` -160 '' ; } if ( number === `` 1 '' ) { degrees = `` -158 '' ; } if ( number === `` 2 '' ) { degrees = `` -156 '' ; } if ( number === `` 3 '' ) { degrees = `` -154 '' ; } if ( number === `` 4 '' ) { degrees = `` -152 '' ; } if ( number === `` 5 '' ) { degrees = `` -150 '' ; } if...
Shorter way to write Jquery If Statement with multiple options for the `` IF ''
JS
I have the following block of code that tracks a click on a button and then records analytics in mixpanel.On its own , activity is NOT being tracked in MixPanel . However , when I add alert ( 'added ' ) ; beneath the mixpanel tracking code , all of a sudden it works perfectly.Why ? Update : since some people asked , th...
< script type= '' text/javascript '' > $ ( '.buy ' ) .click ( function ( ) { var myPart = $ ( ' # part-name ' ) .text ( ) ; var myDistributor = $ ( this ) .closest ( 'tr ' ) .children ( '.distributor ' ) .text ( ) ; mixpanel.track ( `` Buy Part Link '' , { `` PartName '' : myPart , `` Distributor '' : myDistributor } )...
Why does a piece of Javascript only work when I have an alert beneath it ?
JS
I have an array of strings in JavaScript . The array is defined like the following : I need to loop through the array and call a function that runs asynchronously . That function looks like this : I 'm trying to iterate through all of the items in my array and figure out how long it takes to run all of them . I want to...
var myArray = [ ] ; myArray.push ( ' 1 ' ) ; myArray.push ( ' 2 ' ) ; myArray.push ( ' 3 ' ) ; function myAsyncFunction ( id , callback ) { $ .ajax ( { url : '/api/items ' , data : { 'id ' : id } , type : 'POST ' , dataType : 'text ' , success : function ( result ) { if ( callback ) { callback ( ) ; } } , error : funct...
JavaScript Arrays with Async Functions
JS
I am using div to layout a page . The page has two columns . The first column is a map . The second column contains three rows of graphs . I used the code below . The result gives me just one column ( instead of two ) with four rows . What am I doing wrong ?
< ! -- This is where the map will live -- > < div id= '' map-container '' style= '' width:1000px ; height:500px '' > < /div > < ! -- CHARTS ! ! ! -- > < div class= '' row '' > < ! -- row chart -- > < div class= '' col-md-1 '' > < div id= '' rowchart2 '' class= '' dc-chart '' > < /div > < center > < div class= '' title ...
how to use div to layout page
JS
I have an extend method included in my library , making it possible for methods to be added to the core library : In use it looks like so : Users are then able to call the plugin like so : This works but I 'm not exactly happy with the approach and have been trying to find an alternative pattern to make this work . The...
library.prototype.extend = function ( name , plugin ) { library.prototype [ name ] = plugin.init ; for ( var method in plugin ) { if ( method ! == 'init ' ) { library.prototype [ name ] .prototype [ method ] = plugin [ method ] ; } } } ; library.prototype.extend ( 'aReallyInterestingPlugin ' , { //the init method gets ...
Improving the implementation of a plugin architecture