function

methods vs. functions

I keep on getting confused about this design decision a lot of the time when I'm writing programs, but I'm not 100% sure when I should make a function to be a member function of a class, when to leave it as a normal function in which other source files can call the function when the function declaration is exposed in a header file. Does ...

AS3 ... (rest) parameter

Hello, I've tested the following code: function aa(...aArgs):void { trace("aa:", aArgs.length); bb(aArgs); } function bb(...bArgs):void { trace("bb:", bArgs.length); } aa(); //calling aa without any arguments. The output is: aa: 0 //this is expected. bb: 1 //this is not! When I pass empty arguments (aArgs) to bb functi...

PHP - How to get object from array when array is returned by a function?

Hi, how can I get a object from an array when this array is returned by a function? class Item { private $contents = array('id' => 1); public function getContents() { return $contents; } } $i = new Item(); $id = $i->getContents()['id']; // This is not valid? //I know this is possible, but I was looking for a 1 li...

Passing $(this) to jQuery fadeOut callback

I know I need to use a callback so that html() doesn't happen until after fadeOut(), but inside the fadeOut() callback I don't have access to $(this) from .hover. I tried passing the selection using var point, but it's not working. if(!$.browser.msie) { points = $("div.point"); } else { points = $("div.flash"); } Problem Area: $(p...

How to create a template function within a class? (C++)

I know it's possible to make a template function: template<typename T> void DoSomeThing(T x){} and it's possible to make a template class: template<typename T> class Object { public: int x; }; but is it possible to make a class not within a template, and then make a function in that class a template? Ie: //I have no idea if th...

AS3 arguments

Why do you think the code below does not work? What would you change/add to make it work? Any help is appreciated.. function TraceIt(message:String, num:int) { trace(message, num); } function aa(f:Function, ...args):void { bb(f, args); } aa(TraceIt, "test", 1); var func:Function = null; var argum:Array = null; function bb(...

Math equation to calculate different speeds for fade animation

I'm trying to add a fade effect to my form by manually changing the opacity of the form but I'm having some trouble calculating the correct value to increment by the Opacity value of the form. I know I could use the AnimateWindow API but it's showing some unexpected behavior and I'd rather do it manually anyways as to avoid any p/invoke...

calling method of object of object with call_user_func

Hi all, consider this simple scenario: $this->method($arg1, $arg2); Solution: call_user_func_array(array($this,'method'), array($arg1, $arg2)); consider this scenario: $this->object->method($arg1, $arg2); Should this solution work? call_user_func_array(array($this->object,'method'), array($arg1, $arg2)); Or should this work?...

sql server - passing unquoted constants to functions like DATEPART does

i would like to create a function which accepts a constant like the datepart function accepts yy/mm/dd/hh/ like: select datepart(dd, getdate()) i would like to create my own function that accepts dd not char like 'dd' i want select MyFunc(dd, getdate()) and not select MyFunc('dd', getdate()) ...

Same function, different return types for class hierarchy

We have a class hierarchy which looks something like this: class base { }; class derived1 : protected base { private: float m_price; int m_quantity; float m_value; public: // float calculateValue(); }; class derived2 : protected base { private: double m_price; long m_quantity; double m_value; public: // doubl...

Can someone explain me the pack() function in PHP?

Hi, I would like to know more about the pack() function in PHP: http://fi.php.net/manual/en/function.pack.php I know it packs data into binary, but I'm not sure what all those v V n N c C mean and I was wondering if someone could be kind and give me a practical demonstration when to use which formats? The online documentation, for cha...

PHP: Detect invalid characters in a text

Hello! I would like to parse user inputs with PHP. I need a function which tells me if there are invalid characters in the text or not. My draft looks as follows: <?php function contains_invalid_characters($text) { for ($i = 0; $i < 3; $i++) { $text = html_entity_decode($text); // decode html entities } // loop is used ...

Calling a function that resides in the main page from a plugin?

I want to call a function from within plugin, but the function is on the main page and not the plugin's .js file. EDIT I have jQuery parsing a very large XML file and building, subsequently, a large list (1.1 MB HTML file when dynamic content is copied, pasted, then saved) that has expand/collapse functionality through a plugin. The...

F# Static Methods In Class

I'm trying to figure out how to make static methods in a class in F#. Does anyone have any idea how to do this? ...

Where can I find, or how can I create an elegant C++ member function template wrapper mechanism without resporting to boost?

I want to be able to templatize a class on a member function without needing to repeat the arguments of the member function -- i e, derive them automatically. I know how to do this if I name the class based on how many arguments the function takes, but I want to derive that as well. Something like this, although this doesn't work (at le...

How to get an 'array of strings' as a function's return type?

String[] decode(String message) Above is an example. I need to get 2 strings s1 and s2 as the return values for the decode function. How should I proceed? ...

Using an associative array as php function's input

Occasionally I'll write a PHP function with a single input, an associative array containing all of that function's inputs. This has benefits such as not having to remember the correct order of inputs, but I've also noticed it makes implementing changes to large codebases much easier; when I need to add another variable, and that variable...

Making a function only accessible from one other function

How can I declare and define a function so that it is only accessible from a single function? I can declare a function in another function. But since local function definitions are illegal (according to Visual C++) I must define the function at global scope, making it possible for other functions to call it. void f1() { void f1_priv...

Handle either a list or single integer as an argument

A function should select rows in a table based on the row name (column 2 in this case). It should be able to take either a single name or a list of names as arguments and handle them correctly. This is what I have now, but ideally there wouldn't be this duplicated code and something like exceptions would be used intelligently to choose ...

(Ruby, Rails, Javascript) Drag and Drop without bugging the server...?

Hi All, Is there an equivalent of "link_to_function" (instead of ":action") when using "draggable_element"? Basically I need to drag and drop some items and have it reflected locally without contacting the server. My current setup is that I have two DIVs with various list items. I have one full of items with domids "points[selected][...