小编Sam*_*dra的帖子

语音识别在Firefox中不起作用

我正在尝试测试firefox的webspeech-api,但在控制台中遇到错误,提示ReferenceError:SpeechRecognition未定义

我什media.webspeech.recognition.enablemedia.webspeech.synth.enabled在about:config中启用了和标志。

有没有办法使Firefox上的SpeechRecognition工作?

javascript firefox speech-recognition webspeech-api

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

自定义Laravel Passport BearerTokenResponse

目前我使用Laravel Passport进行Laravel安装(league/oauth2-server用于服务器实现).我想在授予oauth2令牌时返回用户ID,因此我可以使用它来识别我的EmberJS应用程序中经过身份验证的用户.

建议的方法是:

创建我自己的类:

use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;

class UserIdBearerTokenResponse extends BearerTokenResponse
{
    protected function getExtraParams(AccessTokenEntityInterface $accessToken)
    {
        return [
            'user_id' => $this->accessToken->getUserIdentifier()
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

修改AuthorizationServer.getResponseType()vendor/league/oauth2-server/src

protected function getResponseType()
{
    if ($this->responseType instanceof ResponseTypeInterface === false) {
        // Return my own class instead of provided one
        $this->responseType = new UserIdBearerTokenResponse();
    }

    $this->responseType->setPrivateKey($this->privateKey);

    return $this->responseType;
}
Run Code Online (Sandbox Code Playgroud)

但是这种方法要求我将vendor/league/oauth2-server/src/AuthorizationServer.php文件添加到我的git repo中.

这对我来说似乎非常混乱和不可靠.是否有更好/更清洁的方法来实现这一目标?

php laravel laravel-passport

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

这是如何在javascript构造函数属性中工作的

我有一个代码如下:

function Cell(center) {
  this.center_cell = center;

  calc_neighbours = function() {
    var points = this.center_cell; 
    console.log(points); // displays undefined 
  };

  this.get_neighbours = function() {
    return calc_neighbours();
  };    
}

var c_points = new Array(8,2);
var cell = new Cell(c_points);
cell.get_neighbours();
Run Code Online (Sandbox Code Playgroud)

放置上面的代码后,该函数cell.get_neighbours()显示为undefined.

现在,如果我稍作修改并列出以下列出的代码,则函数会显示值.为什么会发生这种情况是因为函数范围或javascript对象属性中的变量范围.

以下是显示值的代码:

function Cell(center) {
  this.center_cell = center;

  this.calc_neighbours = function() {
    var points = this.center_cell; 
    console.log(points); // displays undefined 
  };

  this.get_neighbours = function() {
    return this.calc_neighbours();
  };    
}
Run Code Online (Sandbox Code Playgroud)

我没有对功能使用进行任何更改.即

 var c_points = new Array(8,2);
 var cell = …
Run Code Online (Sandbox Code Playgroud)

javascript

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

jQuery替换表中的字符

这是我的桌子

<table>
  <tr>
    <td>"James"</td>
    <td>"do"</td>
    <td>"you</td>
    <td>"like</td>
    <td>"your life"</td>
  </tr>
</table>


<button>Let the magic begin</button>
Run Code Online (Sandbox Code Playgroud)

我想删除所有的"符号所以<td>"James"</td><td>James</td>等等.

我创建了这个函数但是什么也没做.

$("button").on( "click", function(e) {
  $('table').find("tr").each(function() {
      $(this).replace(/\+/g, '');

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

html javascript jquery

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