Search Results

Search found 2 results on 1 pages for 'robotsushi'.

Page 1/1 | 1 

  • Self-Executing Anonymous Function vs Prototype

    - by Robotsushi
    In Javascript there are a few clearly prominent techniques for create and manage classes/namespaces in javascript. I am curious what situations warrant using one technique vs. the other. I want to pick one and stick with it moving forward. I write enterprise code that is maintained and shared across multiple teams, and I want to know what is the best practice when writing maintainable javascript ? I tend to prefer Self-Executing Anonymous Functions however I am curious what the community vote is on these techniques. Prototype : function obj() { } obj.prototype.test = function() { alert('Hello?'); }; var obj2 = new obj(); obj2.test(); Self-Closing Anonymous Function : //Self-Executing Anonymous Function (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = "Bacon Strips"; //Public Method skillet.fry = function() { var oliveOil; addItem( "\t\n Butter \n\t" ); addItem( oliveOil ); console.log( "Frying " + skillet.ingredient ); }; //Private Method function addItem( item ) { if ( item !== undefined ) { console.log( "Adding " + $.trim(item) ); } } }( window.skillet = window.skillet || {}, jQuery )); //Public Properties console.log( skillet.ingredient ); //Bacon Strips //Public Methods skillet.fry(); //Adding Butter & Fraying Bacon Strips //Adding a Public Property skillet.quantity = "12"; console.log( skillet.quantity ); //12 //Adding New Functionality to the Skillet (function( skillet, $, undefined ) { //Private Property var amountOfGrease = "1 Cup"; //Public Method skillet.toString = function() { console.log( skillet.quantity + " " + skillet.ingredient + " & " + amountOfGrease + " of Grease" ); console.log( isHot ? "Hot" : "Cold" ); }; }( window.skillet = window.skillet || {}, jQuery )); //end of skillet definition try { //12 Bacon Strips & 1 Cup of Grease skillet.toString(); //Throws Exception } catch( e ) { console.log( e.message ); //isHot is not defined } I feel that I should mention that the Self-Executing Anonymous Function is the pattern used by the jQuery team. Update When I asked this question I didn't truly see the importance of what I was trying to understand. The real issue at hand is whether or not to use new to create instances of your objects or to use patterns which do not require constructors of the use of the new keyword. I added my own answer, because in my opinion we should make use of patterns which don't use the new keyword. For more information please see my answer.

    Read the article

  • Why does applying this gradient style break my silverlight app ?

    - by Robotsushi
    I am having some issues with applying a gradient to a RadButton. I have a gradient definition in my styles resource dictionairy like so : <LinearGradientBrush x:Key="GridView_HeaderBackground" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF5B5B5B" Offset="1"/> <GradientStop Color="#FF868686"/> <GradientStop Color="#FF4F4F4F" Offset="0.42"/> <GradientStop Color="#FF0E0E0E" Offset="0.43"/> </LinearGradientBrush> When i apply this gradient directly to the background of a RadButton everything works. Here is the button and the template definition: Button <telerik:RadButton Margin="5,10,5,0" Click="RadButton_Click" Tag="30" Content="30 Days" Style="{StaticResource SliderButton}" Background="{StaticResource GridView_HeaderBackground}" /> Template: <!-- Style Template for Slider RadButton --> <Style x:Key="SliderButton" TargetType="telerik:RadButton"> <Setter Property="Height" Value="30" /> <Setter Property="Foreground" Value="#FFFFFF" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Margin" Value="5,2" /> </Style> However when applying this gradient in the resource dictionary, my application will not load it simply gets to the silverlight loading screen and then never proceeds Here is the button and template which breaks my app. Button: <telerik:RadButton Margin="5,10,5,0" Click="RadButton_Click" Tag="30" Content="30 Days" Style="{StaticResource SliderButton}" /> Template: <!-- Style Template for Slider RadButton --> <Style x:Key="SliderButton" TargetType="telerik:RadButton"> <Setter Property="Background" Value="{StaticResource GridView_HeaderBackground}" /> <Setter Property="Height" Value="30" /> <Setter Property="Foreground" Value="#FFFFFF" /> <Setter Property="BorderThickness" Value="0" /> <Setter Property="Margin" Value="5,2" /> </Style> When i observe the js error console in google chrome i notice the following error is produced: "Cannot find a resource with the name/key ResourceWrapper"

    Read the article

1