working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,714 snippets matching: prototype

    public by lbottaro  476235  9  6  2

    JavaScript equivalent to C# String.format

    The code below is the Javascript equivalent to C# String.Format() for replacing elements like {0}, {1}, {2} with parameters. In this case the String prototype is modified, adding the new format() method to all string instances. How to use var mystring = "Hello {0}, how are you? My name is {1}. Bye {0}!" mystring.format("Alice", "Bob") //
    // First, checks if it isn't implemented yet.
    if (!String.prototype.format) {
      String.prototype.format = function() {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, number) { 
          return typeof args[number] != 'undefined'
            ? args[number]
            : match
          ;
        });
      };
    }            

    public by sTiLL-iLL  235389  1  7  15

    ES5 Array funKtion polly-fillerz...

    just in case your browser sucks
    
    // filler for Array.prototype.bind()
    
    if (!Function.prototype.bind) {
      Function.prototype.bind = function(that) {
        if (typeof this !== 'function') {
          throw new TypeError('obj is not callable');
        }
        var a_Argz = Array.prototype.slice.call(arguments, 1), noop = function() {},
            bFnky = this, bnd  = function() {
              return bFnky.apply(this instanceof noop && that? this: that,
                     a_Argz.concat(Array.prototype.slice.call(arguments)));
            };
    
        noop.prototype = this.prototype;
        bnd.prototype = new noop();
        return bnd;
      };
    }
    
    // different approach for isArray()...
    
    function isArray (list) {
      
    }
    
    if (!Array.isArray) {
      Array.isArray = function(argz) {
        return Object.prototype.toString.call(argz) === '[object Array]';
      };
    }
    
    function isArray (list) {
      if (Array.isArray) {
        return Array.isArray(list);
      }
    }
    
    function isArray (list) {
      if (Array.isArray) {
        return Array.isArray(list);
      }
      return Object.prototype.toString.call(list) === '[object Array]';
    }
    
    
    var isArray;
    var isArray = (function () {
      
    })();
    
    var isArray = (function () {
      if (Array.isArray) {
        return Array.isArray;
      }
    })();
    
    var isArray = (function () {
      if (Array.isArray) {
        return Array.isArray;
      }
      return function (list) {
        return Object.prototype.toString.call(list) === '[object Array]';
      };
    })();
    
    function (list) {
      return Object.prototype.toString.call(list) === '[object Array]';
    }                        

    public by bfranzoi  152506  0  5  0

    Simple Object Prototype

    // create your Animal class here
    function Animal(name,numLegs)
    {
        this.name = name;
        this.numLegs = numLegs;
    }
    
    
    // create the sayName method for Animal
    Animal.prototype.sayName = function () {
        console.log("Hi my name is " + this.name);
    } 
    
    // provided code to test above constructor and method
    var penguin = new Animal("Captain Cook", 2);
    penguin.sayName();  

    public by sTiLL-iLL @ SniPitz-KND  2321  3  7  15

    extend, toggleClass, equals, inArray.... functional javascript prototypes

    // functional additions to the Object prototype
     
    Object.prototype.extend = function() {
      if (arguments.length === 0)
        return this;
     
      for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
          if (arguments[i].hasOwnProperty(property))
            this[property] = arguments[i][property];
        }
      }
      return this;
    };
     
     
    Object.prototype.equals = function(x) {
      var p;
      for(p in this) {
        if (typeof(x[p]) == "undefined")
          return false;
      }
      
      for(p in this) {
        if (this[p]) {
          switch(typeof(this[p])) {
            case "object":
              if (!this[p].equals(x[p])) {
                return false;
              }
              break;
            case "function":
              if (typeof(x[p]) == "undefined" ||(p != "equals" && this[p].toString() != x[p].toString())) {
                return false;
              }
              break;
            default:
              if (this[p] != x[p]) {
                return false;
              }
          }
        }
        else {
          if (x[p]) {
            return false;
          }
        }
      }
      
      for(p in x) {
        if(typeof(this[p])=="undefined") {
          return false;
        }
      }
      
      return true;
    };
     
     
    Array.prototype.inArray = function (value) {
      for (var i = 0; i < this.length; i++) {
        if (typeof value === "object") {
        
          // If both are objects, uses the equals function
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }
        }
        else if (this[i] === value) {
          return i;
        }
      }
      
      return false;
    };
     
     
    function toggleClass(id, className) {
      var element = document.getElementById(id);
      var classes = element.className.split(/s+/);
      var length = classes.length;
      var found = classes.inArray(className);
      
      if (found !== false) {
        classes.splice(found, 1);
      }
        
      // The className is not found
      if (length === classes.length) {
        classes.push(className);
      }
        
      element.className = classes.join(" ");
    };

    public by sTiLL-iLL @ SniPitz-KND  4100  1  8  21

    More EveNtIng MaDnEsS!

    A super fast and reliable eventbroker for the browser or server. Made it with Luv!
    
    (function () {
      
    	function Signals () {}
    	var exports = this,
    		signals = Signals.prototype;
      
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	}
    		
    	signals.wen = function (nam, func) {
    		if (!this.sigsMap) {
    			this.sigsMap = {};
    		}
    		if (!this.sigsMap[nam]) {
    			this.sigsMap[nam] = func;
    		} 
    		else if (isAry(this.sigsMap[nam])) {
    			this.sigsMap[nam].push(func);
    		} 
    		else {
    			this.sigsMap[nam] = [this.sigsMap[nam], func];
    		}	
    		return this;
    	};
    	
    	signals.signaled = function(nam, func) {
    		return this.wen(nam, function(evnt){
    			return func(evnt);
    		});
    	};
    
    	signals.removeReceivers = function (nam) {
    		if (!nam) {
    			this.sigsMap = {};
    			return this;
    		}
    		if (this.sigsMap && this.sigsMap[nam]) {
    			this.sigsMap[nam] = null;
    		}
    		return this;
    	};
    	
    	signals.receiverObjects = function (nam) {
    		var recvrLst = this.receivers(nam), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[nam] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	};
    	 
    	signals.receivers = function (nam) {
    		if (!this.sigsMap) {
    			this.sigsMap = {};
    		}
    		if (!this.sigsMap[nam]) {
    			this.sigsMap[nam] = [];
    		}
    		if (!isAry(this.sigsMap[nam])) {
    			this.sigsMap[nam] = [this.sigsMap[nam]];
    		}
    		return this.sigsMap[nam];
    	};
    		
    	signals.addReceiver = signals.wen;
    	signals.signaledOnce = function (nam, func) {
    		var slf = this;
    		function onit () {
    			slf.removeReceiver(nam, wen);
    			func.apply(this, args);
    		}
    		wen.receiver = func;
    		this.onit(nam, wen);	
    		return this;
    	};
    
    	signals.removeReceiver = function (nam, func) {
    		if (this.sigsMap && this.sigsMap[nam]) {
    			var sigLst = this.sigsMap[nam];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    				if (idx < 0) {
    					return this;
    				}
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete this.sigsMap[nam];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete this.sigsMap[nam];
    			}
    		}
    		return this;
    	};
    	 
    	signals._setSignalOnceRV = function (val) {
    		this._signalRtnVal_ = val;
    		return this;
    	};
    
    	signals._getSignalOnceRV = function () {
    		if (this.hasOwnProperty('_signalRtnVal_')) {
    			return this._signalRtnVal_;
    		}
    		else {
    			return true;
    		}
    	};
    	 
    	signals.signal = function (nam, args) {
    		var recvrLst = this.receiverObjects(nam),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signaledOnce === true) {
    						this.removeReceiver(nam, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === this._getSignalOnceRV()) {
    						this.removeReceiver(nam, recvr);
    					}
    				}
    			}
    		}
    		return this;
    	};
    
    	if (typeof module === 'object' && module.exports){
    		module.exports = Signals;
    	}
    	else if (typeof define === 'function' && define.amd) {
    		define(function () {
    			return Signals;
    		});
    	}
    	else {
    		exports.Signals = Signals;
    	}
    	
    }.call(this));
    
    
    var Signals = function () {
    	
    	'use strict';
    	
    	var sigCache = {};
    	
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	}
    	
    	function receiverObjects(eventName) {
    		var recvrLst = receivers(eventName), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[eventName] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	}
    	
    	function receivers(eventName) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = [];
    		}
    		if (!isAry(sigCache[eventName])) {
    			sigCache[eventName] = [sigCache[eventName]];
    		}
    		return sigCache[eventName];
    	}
    	
    	function wen(eventName, func) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = func;
    		} 
    		else if (isAry(sigCache[eventName])) {
    			sigCache[eventName].push(func);
    		} 
    		else {
    			sigCache[eventName] = [sigCache[eventName], func];
    		}
    		return this;
    	}
    	
    	var addReceiver = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	signalReceived = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	dropReceivers = function (eventName) {
    		if (!eventName) {
    			sigCache = {};
    			return this;
    		}
    		if (sigCache && sigCache[eventName]) {
    			sigCache[eventName] = null;
    		}
    		return this;
    	},    
    	signalOnce = function (eventName, func) {
    		var slf = this;
    		function onit () {
    			slf.dropReceiver(eventName, wen);
    			func.apply(this, args);
    		}
    		wen.receiver = func;
    		this.onit(eventName, wen);	
    		return this;
    	},
    	dropReceiver = function (eventName, func) {
    		if (sigCache && sigCache[eventName]) {
    			var sigLst = sigCache[eventName];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    			
    				if (idx < 0) {
    					return this;
    				}
    			
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete sigCache[eventName];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete sigCache[eventName];
    			}
    		}
    		return this;
    	},  
    	setSingleRV = function (val) {
    		singleRtnVal = val;
    		return this;
    	},  
    	getSingleRV = function() {
    		if (sigCache.hasOwnProperty('singleRtnVal')) {
    			return singleRtnVal;
    		}
    		else {
    			return true;
    		}
    	},	 
    	castSignal = function(eventName, args) {
    		var recvrLst = receiverObjects(eventName),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signalOnce === true) {
    						dropReceiver(eventName, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === getSingleRV()) {
    						dropReceiver(eventName, recvr);
    					}
    				}
    			}
    		}
    		return this;
       };
       return {
    		signal: castSignal,
    		signaled: signalReceived,
    		receive: addReceiver,
    		receivers: receivers,
    		receiveOnce: signalOnce,
    		dropReceiver: dropReceiver,
    		dropReceivers: dropReceivers
    	};
    };
    
    exports.Signals = Signals;
    
    

    public by Zenitram.PRO  3525  1  5  1

    How to use Prototype in Object

    It's All in the Genes In object-oriented programming, inheritance allows one class to see and use the methods and properties of another class. You can think of it as a child being able to use his or her parent's money because the child inherits the money. We will learn more about inheritance as we continue this lesson, but for now let's just
    // create your Animal class here
    function Animal(name,numLegs)
    {
        this.name = name;
        this.numLegs = numLegs;
    }
    
    
    // create the sayName method for Animal
    Animal.prototype.sayName = function () {
        console.log("Hi my name is " + this.name);
    } 
    
    // provided code to test above constructor and method
    var penguin = new Animal("Captain Cook", 2);
    penguin.sayName();            

    public by fadzly  1975  0  6  0

    Protoype $$ Selector

    $$('div');
    // -> all DIVs in the document. Same as document.getElementsByTagName('div').
    // Nice addition, the elements you're getting back are already extended!
     $$('#contents');
    // -> same as $('contents'), only it returns an array anyway (even though IDs must
    // be unique within a document).
     $$('li.faux');
    // -> all LI elements with class 'faux'
    
    $$('#contents a[rel]');
    // -> all links inside the element of ID "contents" with a rel attribute
     $$('a[href="#"]');
    // -> all links with a href attribute of value "#" (eyeew!)
     $$('#navbar a', '#sidebar a');
    // -> all links within the elements of ID "navbar" or "sidebar"
    
    $$('a:not([rel~=nofollow])');
    // -> all links, excluding those whose rel attribute contains the word "nofollow"
     $$('table tbody > tr:nth-child(even)');
    // -> all even rows within all table bodies
     $$('div:empty');
    // -> all DIVs without content (i.e., whitespace-only)

    public by heeyahnuh  1942  2  6  2

    Remove items from an Array in Javascript

    remove items from an array starting from the first parameter and ending at the second parameters eg.1-5
    // Enter here the actual content of the snippet.            
    Array.prototype.remove = function (from, to) {
            var rest = this.slice((to || from) + 1 || this.length);
            this.length = from < 0 ? this.length + from : from;
            return this.push.apply(this, rest);
        };

    public by DavidEGrayson  1718  1  3  0

    Prototype, non-working MSYS2 launcher I made a while ago that adds custom entries to its taskbar entry so you can right-click on it and use it to launch different versions of MSYS2.

    Prototype, non-working MSYS2 launcher I made a while ago that adds custom entries to its taskbar entry so you can right-click on it and use it to launch different versions of MSYS2.: msys2launcher.cpp
    #define NTDDI_VERSION NTDDI_WIN7
    #define _WIN32_WINNT _WIN32_WINNT_WIN7
    
    #include <stdio.h>
    #include <unistd.h>
    #include <windows.h>
    #include <propvarutil.h>
    #include <shellapi.h>
    #include <propsys.h>
    #include <propkey.h>
    #include <shobjidl.h>
    #include <objectarray.h>
    
    wchar_t appId[] = L"davidegrayson/msys2launcher";
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    int setAppId(HWND);
    int setupTaskbar(HWND);
    int setupTasks(void);
    int launchMsys2(const char * msystem);
    
    DWORD wmTaskbarButtonCreated = -1;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR szCmdLine, int iCmdShow)
    {
        wmTaskbarButtonCreated = RegisterWindowMessage("TaskbarButtonCreated");
    
        setvbuf(stderr, NULL, _IONBF, 0);
    
        if(strcmp(szCmdLine, "msys2") == 0)
        {
            return launchMsys2("MSYS2");
        }
    
        static char appName[] = "testwin32";
    
        WNDCLASSEX wndclass;
        wndclass.cbSize = sizeof(wndclass);
        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc = WndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wndclass.lpszClassName = appName;
        wndclass.lpszMenuName = NULL;
        RegisterClassEx(&wndclass);
    
        HWND hwnd = CreateWindow(appName, szCmdLine,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, hInstance, NULL);
    
        setAppId(hwnd);
    
        ShowWindow(hwnd, iCmdShow);
        UpdateWindow(hwnd);
    
        while(1)
        {
            MSG msg;
            BOOL bRet = GetMessage(&msg, NULL, 0, 0);
            if (bRet == -1)
            {
                // Error
                fprintf(stderr, "GetMessage returned -1\n");
                return 1;
            }
            else if (bRet == 0)
            {
                // WM_QUIT message
                return msg.wParam;
            }
    	TranslateMessage(&msg);
    	DispatchMessage(&msg);
        }
    }
    
    int setAppId(HWND hwnd)
    {
        PROPVARIANT pv;
        HRESULT result = InitPropVariantFromString(appId, &pv);
        if (result != S_OK)
        {
            fprintf(stderr, "InitPropVariantFromString error\n");
            return -1;
        }
    
        IPropertyStore* pps;
        result = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps));
        if (result != S_OK)
        {
            fprintf(stderr, "SHGetPropertyStoreForWindow failed\n");
            return -1;
        }
    
        result = pps->SetValue(PKEY_AppUserModel_ID, pv);
        if (result != S_OK)
        {
            fprintf(stderr, "SetValue failed\n");
            return -1;
        }
    
        result = pps->Commit();
        if (result != S_OK)
        {
            fprintf(stderr, "Commit failed\n");
            return -1;
        }
    
        return 0;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (iMsg)
        {
        case WM_CREATE:
            return 0;
    
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
    	HDC hdc = BeginPaint(hwnd, &ps);
    	TextOut(hdc, 100, 100, "Hello, world!", 13);
    	EndPaint(hwnd, &ps);
    	return 0;
        }
    
        case WM_DESTROY:
    	PostQuitMessage(0);
    	return 0;
        }
    
        if (iMsg == wmTaskbarButtonCreated)
        {
            setupTaskbar(hwnd);
            setupTasks();
        }
    
        return DefWindowProc(hwnd, iMsg, wParam, lParam);
    }
    
    int setupTaskbar(HWND hwnd)
    {
        fprintf(stderr, "Taskbar button created\n");
    
        ITaskbarList3 * ptl;
        HRESULT result = CoCreateInstance(
            CLSID_TaskbarList, NULL, CLSCTX_ALL,
            IID_ITaskbarList3, (void**)&ptl);
        if (FAILED(result))
        {
            fprintf(stderr, "CoCreateInstance for TaskBarList3 failed\n");
            return 1;
        }
    
        ptl->Release();
        return 0;
    }
    
    int setupTasks()
    {
        HRESULT result;
    
        ICustomDestinationList * cdl;
        result = CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_ALL, IID_PPV_ARGS(&cdl));
        if (FAILED(result))
        {
            fprintf(stderr, "CoCreateInstance for CustomDestinationList failed.\n");
            return 1;
        }
    
        result = cdl->SetAppID(appId);
        if (FAILED(result))
        {
            fprintf(stderr, "Setting app ID for CDL failed.\n");
            return 1;
        }
    
        IObjectArray * removedItems;
        UINT minSlots;
        result = cdl->BeginList(&minSlots, IID_PPV_ARGS(&removedItems));
        if (FAILED(result))
        {
            fprintf(stderr, "BeginList failed\n");
            return 1;
        }
    
        IObjectCollection * tasks;
        result = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&tasks));
        if (FAILED(result))
        {
            fprintf(stderr, "Creating collection failed\n");
            return 1;
        }
    
        {
            IShellLinkW * shellLink;
            result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
            if (FAILED(result))
            {
                fprintf(stderr, "Creating a ShellLink failed.\n");
                return 1;
            }
    
            shellLink->SetArguments(L"msys2");
            shellLink->SetDescription(L"Launch the MSYS2 Shell");
            shellLink->SetIconLocation(L"C:\\msys64\\msys2.ico", 0);
            shellLink->SetPath(L"C:\\Users\\David\\Documents\\msys2-launcher\\msys2launcher.exe");
    
            IPropertyStore * propertyStore;
            if (FAILED(shellLink->QueryInterface(&propertyStore)))
            {
                fprintf(stderr, "Converting ShellLink to IPropertyStore failed.\n");
                return 1;
            }
    
            PROPVARIANT propertyValue;
            InitPropVariantFromString(L"MSYS2 Shell", &propertyValue);
            propertyStore->SetValue(PKEY_Title, propertyValue);
            propertyStore->Commit();
            PropVariantClear(&propertyValue);
            propertyStore->Release();
    
            tasks->AddObject(shellLink);
            shellLink->Release();
        }
    
        IObjectArray * tasksArray;
        result = tasks->QueryInterface(&tasksArray);
        if (FAILED(result))
        {
            fprintf(stderr, "Converting to array failed\n");
            return 1;
        }
    
        result = cdl->AppendCategory(L"Tasks", tasks);
        if (FAILED(result))
        {
            fprintf(stderr, "Appending category failed: %#lx\n", result);
            return 1;
        }
    
        result = cdl->CommitList();
        if (result != S_OK)
        {
            fprintf(stderr, "CommitList failed\n");
            return 1;
        }
    
        removedItems->Release();
        tasks->Release();
        tasksArray->Release();
        return 0;
    }
    
    int launchMsys2(const char * msystem)
    {
        fprintf(stderr, "Launching msys2 shell\n");
    
        STARTUPINFO startupInfo;
        ZeroMemory(&startupInfo, sizeof(startupInfo));
        startupInfo.cb = sizeof(startupInfo);
    
        // TODO: fill in startupInfo
    
        PROCESS_INFORMATION info;
        ZeroMemory(&info, sizeof(info));
    
        BOOL success = SetEnvironmentVariable("MSYSTEM", msystem);
        if (!success)
        {
            fprintf(stderr, "Failed to set MSYSTEM.\n");
            return 0;
        }
    
    
        char commandLine[] = "mintty --option AppID=davidegrayson/msys2launcher -i /msys2.ico /usr/bin/bash --login";
        success = CreateProcess(
            "C:\\msys64\\usr\\bin\\mintty.exe",
            commandLine,
            NULL,
            NULL,
            FALSE,
            0,
            NULL,  // lpEnvironment
            NULL,  // lpCurrentDirectory
            &startupInfo,
            &info
            );
        if (!success)
        {
            fprintf(stderr, "CreateProcess failed\n");
            return 1;
        }
    
        CloseHandle(info.hProcess);
        CloseHandle(info.hThread);
        return 0;
    }
    
    
    

    public by ManuelAurora  371  0  5  0

    Prototype pattern. Copying protocol

    // Enter here the actual content of the snippet.						
    public protocol Copying: class {
        init(_ prototype: Self)
    }
    
    extension Copying {
        public func copy() -> Self {
            return type(of: self).init(self)
        }
    }
    				
    extension Array where Element: Copying {
      public func deepCopy() -> [Element] {
        return map { $0.copy() }
      }
    }		
    • Public Snippets
    • Channels Snippets