我在自定義grunt任務中遇到錯誤。下面我發佈有關該問題的簡單測試案例:錯誤「Object has no method'endsWith'」on custom grunt task
Gruntfile.js
module.exports = function(grunt){
grunt.task.registerTask('endsWith', 'Test of string.prototype.endsWith', function(){
var value = grunt.option('value');
grunt.log.writeln(typeof value);
grunt.log.writeln(value.endsWith('bar'));
})
};
測試
> grunt endsWith --value=foobar
Running "endsWith" task
string
Warning: Object foobar has no method 'endsWith' Use --force to continue.
Aborted due to warnings.
Execution Time (2016-02-12 16:15:19 UTC)
Total 12ms
這就像咕嚕不承認String.proptotype.endsWith功能。這是正常的嗎?
編輯:我使用節點v0.10.4
node'您運行的是什麼版本的'? (運行'node -v'來查找) –