Skip to main content

Posts

Showing posts with the label syntax

var x, y = "foo"; Can this be accomplished?

Since it is possible to do: var x = 'foo', y = 'foo'; Would this also be possible? var x, y = 'foo'; I tried it, however x becomes undefined. I know this may seem like a silly or redundant question, but if I'm curious about something, why not ask? Also you will probably wonder why I would need two variables equal to the same thing in scope . That is not the point of the question. I'm just curious. Source: Tips4all

What does | in this code mean?

function foo() {} var bar = foo <| function() {}; This is the first time I've seen something like this. What does <| mean? Source: https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp1.js Source: Tips4all

PHP if else - proper use of "else&rdquo;

A professor told me long ago to use else when "chaining" multiple conditions in a series (I was still learning). Now that I've been tinkering with several frameworks and CMS years later, I find it quite amusing that what I was taught to do isn't necessarily so. I was taught to use else in between a series of conditions: function double(param){ if(param==1){ return param+=1; } else if(param==2){ return param+=2; } else{ return false; } } Nowadays, I seem to see this, which I was warned long ago NOT to do: function double(param){ if(param==1){ return param+=1; } if(param==2){ return param+=2; } return false; } This sample code might not work, but the idea is there: Is it necessary to use else in between every condition? If so (or not so), what should I look out for when using either way? There must be something that caused my professor to tell me such thing.

jQuery Sortable UI Syntax Issue

Im not quite sure what to search for to sort out this problem. I am getting syntax error with the following code because i have 2 (no idea what to call them) in the .sortable options. Would you be able to tell me what i have done wrong with this code? Im using a placeholder and also a connectWith from this page http://jqueryui.com/demos/sortable/#portlets and there doesnt seem to be any examples showing how to write both of them at the same time. The syntax error is not there when i comment out placeholder: "placeholder-highlighting" or connectWith: ".sortable-content" My code is below: $(function() { $( ".sortable-content" ).sortable({ placeholder: "placeholder-highlighting" connectWith: ".sortable-content" }); $( ".sortable" ).disableSelection(); }); Bonus points for telling me what they are called!

Set variable within another context

I have the following function "use strict"; function Player { this.width; this.height; this.framesA = 5; this.image = new Image(); this.image.onload = function () { width = this.width; height = this.height / framesA; } this.image.src = "Images/angel.png"; } How can I make this code to work? I want the width and height in the Player function be inalized with the width and the height of the image when the onload function is called. I need this to work with strict mode (A must). If this should be accomplished another way feel free to teach. EDIT: I updated the code to reflect a more realistic situation(I didn't know this will be so complicated) EDIT 2: Another update to the code. I didn't notice that I wrote var insted of this. Sorry. Thanks in advance