小编sea*_*ick的帖子

ES6迭代类方法

鉴于此课程; 我将如何迭代它包含的方法?

class Animal {
    constructor(type){
        this.animalType = type;
    }
    getAnimalType(){
        console.log('this.animalType: ', this.animalType );
    }
}

let cat = window.cat = new Animal('cat')
Run Code Online (Sandbox Code Playgroud)

我试过的是以下但没有成功:

for (var each in Object.getPrototypeOf(cat) ){
    console.log(each);
}
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

34
推荐指数
5
解决办法
1万
查看次数

从函数返回整数数组

我正在尝试从函数返回一个整数数组,对数字进行排序然后将所有内容传递回main.我没有在这段代码中分配和释放内存.我只是想看看它是否真的有效.编译器标记语句的错误b=sort(a).它说它不可分配,这是有道理的.输入整数不是指针.有没有办法将整数数组声明为指针?如 :

int *a[5]={3,4}

#include <stdio.h>
#include <stdlib.h>
int *sort(int *input_array);

int *sort(int *input_array)
{
    return input_array;
}

int main()
{
    int a[5]={3,4};
    int b[5];
    b=sort(a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

8
推荐指数
2
解决办法
4万
查看次数

将回调转变为承诺

我正在使用google maps api,这段代码正在异步返回一个地方列表.如何在调用所有数据时调用此函数并使其触发?这是我迄今为止尝试过的 -

$.search = function(boxes) {

    function findNextPlaces(place_results, searchIndex) {
        var dfd = $.Deferred();
        if (searchIndex < boxes.length) {
            service.radarSearch({
                bounds: boxes[searchIndex],
                types: ["food"]
            }, function (results, status) {
                if (status != google.maps.places.PlacesServiceStatus.OK) {
                    return dfd.reject("Request["+searchIndex+"] failed: "+status);
                }
                console.log( "bounds["+searchIndex+"] returns "+results.length+" results" );
                for (var i = 0, result; result = results[i]; i++) {
                    var marker = createMarker(result);
                    place_results.push(result.reference); // marker?
                }
            });
            return dfd.then(findNextPlaces);
        } else {
            return dfd.resolve(place_results).promise();
        }
    }

    return findNextPlaces([], 0);
};
Run Code Online (Sandbox Code Playgroud)

javascript

6
推荐指数
2
解决办法
2058
查看次数

为什么HEAD领先于大师?

我有HEAD和我的origin/master同步,但是我的主人在两次提交后面.调用git branch -a显示我与16e6202(master)分离.有人可以解释这意味着什么吗?

* e3acad6 (HEAD, origin/master) 14-delete task feature added
* 26641b1 13-edit task feature added
* 16e6202 (master) 12-full tasks example from beginning
Run Code Online (Sandbox Code Playgroud)

我怎样才能再次与主人调和HEAD?

git

4
推荐指数
1
解决办法
1545
查看次数

Backbone this.el vs this.$ el

对于给定的例子,this.el&之间有什么区别?this.$el

我理解this.$el指向jQuery对象this.el,在这种情况下是'li'.

当我渲染视图时,我可以选择this.el,或者this.$el.当我引用jQuery对象时,如何向页面呈现内容?我可以看到如何使用this.$el.html(property),指向html,但为什么追加this.$el和渲染是让我困惑的原因.

var Person = Backbone.Model.extend({
    defaults: {
        name: 'John Doe',
        age: 30,
        occupation: 'worker'
    }
});

var PersonView = Backbone.View.extend({
    tagName: 'li',

    initialize: function() {
        this.render();
    },

    render: function() {
        var out = this.$el.html(this.model.get('name') + this.model.get('occupation'));
        console.log(this, this.el, this.$el, out);
        $('body').append(this.$el);
    },

});

var person = new Person;
var personview = new PersonView({model: person});
Run Code Online (Sandbox Code Playgroud)

javascript jquery backbone.js

3
推荐指数
1
解决办法
4992
查看次数

Angularjs:ng-bind-html&ng-repeat

我有一个视图,我从数据库中检索此模板后我正在更新:

<div class="row" ng-repeat="post in posts">
        <div class="col-lg-9 col-lg-offset-2">        
          <!-- blog entry -->
          <br ng-hide="$last">
          <h1><a href="{{'#/post/' + post.title}}">{{post.title}} </a></h1>
          <p><span class="glyphicon glyphicon-time"></span> Posted on {{ post.time_Date | date:'MM/dd/yyyy @ h:mma'}} </p>
          <div class="image_Center">
            <!-- <img ng-src="{{post.imageUrl}}" width="550" height="450"> -->
            <img ng-src="{{post.imageUrl}}" width="450" height="350">
          </div>
          <br>
          <br>
          <div ng-bind-html="TrustDangerousSnippet()">
            <p>{{post.post}}</p>
          </div>
............not properly closed(huge template)
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用我存储的markdown文本更新{{post.post}}并使用我的控制器正确显示它.代码如下:

$scope.posts = input_data;
$scope.TrustDangerousSnippet = function() {
  return $sce.trustAsHtml(input_data.post);
};      
Run Code Online (Sandbox Code Playgroud)

input_data是来自我的服务器的JSON对象(博客文章)的集合.问题是没有显示整个对象,但如果要显示其中一个对象,它将呈现给页面.可能是什么问题呢?

$scope.posts = input_data;
$scope.TrustDangerousSnippet = function() {
  return $sce.trustAsHtml(input_data[1].post);
};      
Run Code Online (Sandbox Code Playgroud)

这是否与正确使用ng-repeat有关?

angularjs angularjs-scope angularjs-ng-repeat

3
推荐指数
1
解决办法
5353
查看次数

sed在jenkins上失败,但在本地工作

这个命令似乎在本地工作,但在jenkins上失败了

sed -i '' "s/\/styleguide//g" .gitignore
Run Code Online (Sandbox Code Playgroud)

这是一个解析错误,尽管它说无法找到该文件.我知道这一点,因为运行cat打印文件内容.想什么?

sed: can't read s/\/\styleguide//g: No such file or directory
Run Code Online (Sandbox Code Playgroud)

terminal continuous-integration sed sh jenkins

2
推荐指数
1
解决办法
412
查看次数

递归深度扁平化的时间复杂度

这个递归展平函数的运行时间是多少?我的猜测是它是线性的;有人可以解释为什么吗?

const arr = [
  [14, [45, 60], 6, [47, [1, 2, [14, [45, 60], 6, [47, [1, 2]], 9]]], 9],
];

function flatten(items) {
  const flat = [];

  items.forEach(item => {
    if (Array.isArray(item)) {
      flat.push(...flatten(item));
    } else {
      flat.push(item);
    }
  });

  return flat;
}
Run Code Online (Sandbox Code Playgroud)

javascript recursion big-o

1
推荐指数
1
解决办法
2513
查看次数

使用引用时,Typescript Omit 不会显示错误

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

interface objInterface {
  first: string;
  second: string;
}

const obj = {
  first: "first",
  second: "second"
};

const out: Omit<objInterface, "first"> = obj;
Run Code Online (Sandbox Code Playgroud)

我原以为这会出现一些智能感知错误,但事实并非如此。然而,这确实显示了一些错误,有人知道为什么吗?

const out: Omit<objInterface, "first"> = {
  first: 'first',
  second: 'second'
};
Run Code Online (Sandbox Code Playgroud)

typescript typescript-types

1
推荐指数
1
解决办法
3801
查看次数

修改列表类

我正在使用Scala中的函数编程,前几章定义了这种类型的数据结构:

sealed trait List[+A]
case object Nil extends List[Nothing]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
Run Code Online (Sandbox Code Playgroud)

当我尝试定义这样的链表时; 它按预期工作:

val nums: List[Int] = Cons(1, Cons(2, Cons(3, Nil)));
Run Code Online (Sandbox Code Playgroud)

我正在尝试定义这样的链接列表,但是我得到了编译错误(类型为scala.collection.immutable.List [Int]的表达式不符合预期类型List [Int]:

val nums: List[Int] = List[Int](1, 2, 3)
Run Code Online (Sandbox Code Playgroud)

我的问题是 - 1)声明数据结构是否修改了List的内部类?2)为什么不能使用第二种结构?

functional-programming scala

0
推荐指数
1
解决办法
62
查看次数