Skip to content

Instantly share code, notes, and snippets.

@Stason4ik1986
Stason4ik1986 / js-patterns-4.md
Created August 6, 2019 05:57 — forked from Sha1fei/js-patterns-4.md
JS Шаблоны 4. Шаблоны проектирования

JS Шаблоны 4. Шаблоны проектирования

Содержание

  • Singleton
  • Factory
  • Iterator
  • Strategy
  • Facade
  • Proxy
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Payment Method</title>
<link href="style.css" rel="stylesheet"></head>
<body>
<div class="gray-block">
<div class="payment-method">

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array): T[] 🔒 ES3
@Stason4ik1986
Stason4ik1986 / play.js
Created February 25, 2018 10:38 — forked from pbakondy/play.js
Play with Object.prototype.toString.call()
// under Google Chrome 36
Object.prototype.toString.call([])
// "[object Array]"
Object.prototype.toString.call(function(){})
// "[object Function]"
Object.prototype.toString.call({})
// "[object Object]"
Object.prototype.toString.call(null)
// "[object Null]"
//function.php
function create_posttype() {
register_post_type('projects',
array(
'labels' => array(
'name' => 'Проекты',
'singular_name' => 'Проект',
'add_new' => 'Добавить новый'
),
function my_login_logo(){
echo '
<style type="text/css">
#login h1 a { background: url('. get_bloginfo('template_directory') .'/img/logo.png) no-repeat -7px -9px !important; }
</style>';
}
add_action('login_head', 'my_login_logo');
/* Ставим ссылку с логотипа на сайт, а не на wordpress.org */
add_filter( 'login_headerurl', create_function('', 'return get_home_url();') );
@Stason4ik1986
Stason4ik1986 / WordPress Loop for last Posts
Created February 19, 2016 11:01
WordPress Loop for last Posts
<?php
$args = array(
'cat' => 6,
'post_type' => 'photos',
'posts_per_page' => 5
);
$new_query = new WP_Query( $args ); ?>
<?php if($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post(); ?>
<?php the_content();?>
@Stason4ik1986
Stason4ik1986 / WordPress use post thumbnail as div background
Last active February 17, 2016 13:33
WordPress use post thumbnail as div background
<?php if ( have_posts() ) : query_posts('p=1');
while (have_posts()) : the_post(); ?>
<div <?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
printf( ' style="background-image: url(%s);"', $image_src[0] );
}?> ></div>
<?php endwhile; endif; wp_reset_query(); ?>
@Stason4ik1986
Stason4ik1986 / Replace all SVG images with inline SVG
Created January 19, 2016 12:57
Replace all SVG images with inline SVG
//HTML
<img class="img-svg" src="img/..">
//JS
$('img.img-svg').each(function(){
var $img = $(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');